RESOLVED FIXED 233760
Move content filtering to Networking process
https://bugs.webkit.org/show_bug.cgi?id=233760
Summary Move content filtering to Networking process
Per Arne Vollan
Reported 2021-12-02 07:45:01 PST
Moving content filtering to the Networking process will enable us to further strengthen the WebContent process' sandbox.
Attachments
Patch (42.96 KB, patch)
2021-12-02 08:04 PST, Per Arne Vollan
ews-feeder: commit-queue-
Patch (42.76 KB, patch)
2021-12-02 08:58 PST, Per Arne Vollan
no flags
Patch (42.79 KB, patch)
2021-12-02 14:56 PST, Per Arne Vollan
ews-feeder: commit-queue-
Patch (42.71 KB, patch)
2021-12-02 15:55 PST, Per Arne Vollan
no flags
Patch (47.97 KB, patch)
2021-12-05 23:26 PST, Per Arne Vollan
no flags
Patch (48.45 KB, patch)
2021-12-06 02:03 PST, Per Arne Vollan
no flags
Patch (50.08 KB, patch)
2021-12-07 02:15 PST, Per Arne Vollan
no flags
Patch (48.64 KB, patch)
2021-12-07 04:42 PST, Per Arne Vollan
no flags
Patch (50.28 KB, patch)
2021-12-07 04:51 PST, Per Arne Vollan
no flags
Patch (49.00 KB, patch)
2021-12-07 09:12 PST, Per Arne Vollan
no flags
Patch (48.80 KB, patch)
2021-12-07 09:31 PST, Per Arne Vollan
ews-feeder: commit-queue-
Patch (48.80 KB, patch)
2021-12-07 09:34 PST, Per Arne Vollan
ews-feeder: commit-queue-
Patch (48.85 KB, patch)
2021-12-07 10:46 PST, Per Arne Vollan
no flags
Patch (50.51 KB, patch)
2021-12-09 08:25 PST, Per Arne Vollan
no flags
Patch (48.39 KB, patch)
2021-12-09 11:34 PST, Per Arne Vollan
ews-feeder: commit-queue-
Patch (48.39 KB, patch)
2021-12-09 12:42 PST, Per Arne Vollan
no flags
Patch (48.40 KB, patch)
2022-02-17 09:24 PST, Per Arne Vollan
no flags
Patch (48.11 KB, patch)
2022-02-17 11:22 PST, Per Arne Vollan
no flags
Patch (49.34 KB, patch)
2022-02-17 13:30 PST, Per Arne Vollan
no flags
Patch (52.35 KB, patch)
2022-02-18 13:12 PST, Per Arne Vollan
no flags
Patch (52.75 KB, patch)
2022-02-18 13:41 PST, Per Arne Vollan
bfulgham: review+
Patch (53.06 KB, patch)
2022-02-18 16:39 PST, Per Arne Vollan
no flags
Patch (53.05 KB, patch)
2022-02-18 16:57 PST, Per Arne Vollan
no flags
Per Arne Vollan
Comment 1 2021-12-02 08:04:47 PST
Per Arne Vollan
Comment 2 2021-12-02 08:05:23 PST
WIP patch.
Per Arne Vollan
Comment 3 2021-12-02 08:58:53 PST
Per Arne Vollan
Comment 4 2021-12-02 14:56:38 PST
Per Arne Vollan
Comment 5 2021-12-02 15:55:57 PST
Alex Christensen
Comment 6 2021-12-02 16:23:15 PST
Comment on attachment 445784 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=445784&action=review > Source/WTF/wtf/PlatformEnableCocoa.h:168 > +#define ENABLE_CONTENT_FILTERING_IN_NETWORKING_PROCESS ENABLE_CONTENT_FILTERING Is there a reason we can't just do this everywhere?
Per Arne Vollan
Comment 7 2021-12-03 12:23:00 PST
(In reply to Alex Christensen from comment #6) > Comment on attachment 445784 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=445784&action=review > > > Source/WTF/wtf/PlatformEnableCocoa.h:168 > > +#define ENABLE_CONTENT_FILTERING_IN_NETWORKING_PROCESS ENABLE_CONTENT_FILTERING > > Is there a reason we can't just do this everywhere? That's a good point. I will enable for all different platforms. Thanks for reviewing!
Per Arne Vollan
Comment 8 2021-12-05 23:26:45 PST
Per Arne Vollan
Comment 9 2021-12-06 02:03:44 PST
Per Arne Vollan
Comment 10 2021-12-07 02:15:55 PST
Radar WebKit Bug Importer
Comment 11 2021-12-07 04:39:26 PST
Per Arne Vollan
Comment 12 2021-12-07 04:42:32 PST
Per Arne Vollan
Comment 13 2021-12-07 04:51:11 PST
Per Arne Vollan
Comment 14 2021-12-07 09:12:54 PST
Per Arne Vollan
Comment 15 2021-12-07 09:31:07 PST
Per Arne Vollan
Comment 16 2021-12-07 09:34:41 PST
Per Arne Vollan
Comment 17 2021-12-07 10:46:27 PST
Per Arne Vollan
Comment 18 2021-12-09 08:25:25 PST
Per Arne Vollan
Comment 19 2021-12-09 11:34:20 PST
Per Arne Vollan
Comment 20 2021-12-09 12:42:33 PST
Per Arne Vollan
Comment 21 2021-12-09 13:30:58 PST
Per Arne Vollan
Comment 22 2021-12-09 13:32:52 PST
Per Arne Vollan
Comment 23 2022-02-17 09:24:24 PST
Per Arne Vollan
Comment 24 2022-02-17 11:22:12 PST
Per Arne Vollan
Comment 25 2022-02-17 13:30:20 PST
Alex Christensen
Comment 26 2022-02-17 13:47:24 PST
Comment on attachment 452424 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=452424&action=review > Source/WTF/wtf/PlatformEnableCocoa.h:169 > +#define ENABLE_CONTENT_FILTERING_IN_NETWORKING_PROCESS ENABLE_CONTENT_FILTERING I'm still not convinced we need this. I think it ought to be the same everywhere. I don't see any need to have it different on newer OSes. > Source/WebCore/loader/ContentFilter.cpp:279 > +#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS) > +void ContentFilter::deliverResourceData(const SharedBuffer& buffer, size_t encodedDataLength) > +#else > void ContentFilter::deliverResourceData(CachedResource& resource) > +#endif I think it would be better to keep the same signature in both cases. > Source/WebCore/loader/SubstituteData.h:64 > + template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, SubstituteData&); Could you use the modern decoder that returns a std::optional<SubstituteData> instead? > Source/WebKit/WebProcess/Network/WebResourceLoader.h:37 > +#include <WebCore/SubstituteData.h> I think this can be a declaration instead of including the whole header. > Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in:42 > + ContentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler unblockHandler, String unblockRequestDeniedScript) I don't understand how a ContentFilterUnblockHandler can be serialized when it contains a std::function. Do we just lose that when going to a different process? Is that ok? > WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme:160 > + buildConfiguration = "Release" This change should probably not be included. > WebKit.xcworkspace/xcshareddata/xcschemes/All Tools.xcscheme:99 > + buildConfiguration = "Release" ditto
Per Arne Vollan
Comment 27 2022-02-18 13:12:22 PST
Per Arne Vollan
Comment 28 2022-02-18 13:41:37 PST
Per Arne Vollan
Comment 29 2022-02-18 13:55:44 PST
(In reply to Alex Christensen from comment #26) > Comment on attachment 452424 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=452424&action=review > > > Source/WTF/wtf/PlatformEnableCocoa.h:169 > > +#define ENABLE_CONTENT_FILTERING_IN_NETWORKING_PROCESS ENABLE_CONTENT_FILTERING > > I'm still not convinced we need this. I think it ought to be the same > everywhere. I don't see any need to have it different on newer OSes. > The reasoning behind the feature flag is to land with the feature flag off by default, and then enable when we believe there are no regressions. This patch does not enable the feature. After enabling, I expect that the feature flag and obsolete code will be deleted quickly. > > Source/WebCore/loader/ContentFilter.cpp:279 > > +#if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS) > > +void ContentFilter::deliverResourceData(const SharedBuffer& buffer, size_t encodedDataLength) > > +#else > > void ContentFilter::deliverResourceData(CachedResource& resource) > > +#endif > > I think it would be better to keep the same signature in both cases. > Fixed! > > Source/WebCore/loader/SubstituteData.h:64 > > + template<class Decoder> static WARN_UNUSED_RETURN bool decode(Decoder&, SubstituteData&); > > Could you use the modern decoder that returns a > std::optional<SubstituteData> instead? > Done. > > Source/WebKit/WebProcess/Network/WebResourceLoader.h:37 > > +#include <WebCore/SubstituteData.h> > > I think this can be a declaration instead of including the whole header. > Fixed. > > Source/WebKit/WebProcess/Network/WebResourceLoader.messages.in:42 > > + ContentFilterDidBlockLoad(WebCore::ContentFilterUnblockHandler unblockHandler, String unblockRequestDeniedScript) > > I don't understand how a ContentFilterUnblockHandler can be serialized when > it contains a std::function. Do we just lose that when going to a different > process? Is that ok? > Ah, that is a good catch! I have addressed this in the latest patch by calling the function requestUnblockAsync in the Networking process instead. > > WebKit.xcworkspace/xcshareddata/xcschemes/All Source.xcscheme:160 > > + buildConfiguration = "Release" > > This change should probably not be included. > > > WebKit.xcworkspace/xcshareddata/xcschemes/All Tools.xcscheme:99 > > + buildConfiguration = "Release" > > ditto Done. Thanks for reviewing!
Brent Fulgham
Comment 30 2022-02-18 16:12:16 PST
Comment on attachment 452576 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=452576&action=review r=me > Source/WebCore/loader/ContentFilter.cpp:122 > + LOG(ContentFiltering, "ContentFilter will start filtering main resource at <%s>.\n", url.string().ascii().data()); This is privacy-impacting. I think you need to use the %{sensitive}s logging declaration here. > Source/WebCore/loader/ContentFilter.cpp:176 > + LOG(ContentFiltering, "ContentFilter received %zu bytes of data from <%s>.\n", data.size(), url().string().ascii().data()); Ditto (even though the old code added logging with the secret information). > Source/WebCore/loader/ContentFilter.cpp:216 > + LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%s>.\n", url().string().ascii().data()); Ditto. > Source/WebCore/loader/ContentFilter.cpp:271 > + LOG(ContentFiltering, "ContentFilter decided load should be %s for main resource at <%s>.\n", state == State::Allowed ? "allowed" : "blocked", url().string().ascii().data()); Ditto. > Source/WebCore/loader/ContentFilter.cpp:355 > + for (unsigned i = 0; i < m_buffers.size(); i++) It seems like this could be a modern C++ loop: for (auto& buffer in m_buffers) deliverResourceData(*buffer.buffer, buffer.encodedDataLength); > Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:1296 > + shouldFilter = m_contentFilter && !m_contentFilter->continueAfterDataReceived(sharedBuffer, m_bufferedDataEncodedDataLength); Why not: bool shouldFilter = m_contentFilter .... <<ETC>> > Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:614 > + if (!page) I'd just do: if (auto* page = ... page->reload....
Per Arne Vollan
Comment 31 2022-02-18 16:39:35 PST
Per Arne Vollan
Comment 32 2022-02-18 16:41:31 PST
(In reply to Brent Fulgham from comment #30) > Comment on attachment 452576 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=452576&action=review > > r=me > > > Source/WebCore/loader/ContentFilter.cpp:122 > > + LOG(ContentFiltering, "ContentFilter will start filtering main resource at <%s>.\n", url.string().ascii().data()); > > This is privacy-impacting. I think you need to use the %{sensitive}s logging > declaration here. > > > Source/WebCore/loader/ContentFilter.cpp:176 > > + LOG(ContentFiltering, "ContentFilter received %zu bytes of data from <%s>.\n", data.size(), url().string().ascii().data()); > > Ditto (even though the old code added logging with the secret information). > > > Source/WebCore/loader/ContentFilter.cpp:216 > > + LOG(ContentFiltering, "ContentFilter will finish filtering main resource at <%s>.\n", url().string().ascii().data()); > > Ditto. > > > Source/WebCore/loader/ContentFilter.cpp:271 > > + LOG(ContentFiltering, "ContentFilter decided load should be %s for main resource at <%s>.\n", state == State::Allowed ? "allowed" : "blocked", url().string().ascii().data()); > > Ditto. > > > Source/WebCore/loader/ContentFilter.cpp:355 > > + for (unsigned i = 0; i < m_buffers.size(); i++) > > It seems like this could be a modern C++ loop: > > for (auto& buffer in m_buffers) > deliverResourceData(*buffer.buffer, buffer.encodedDataLength); > > > Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp:1296 > > + shouldFilter = m_contentFilter && !m_contentFilter->continueAfterDataReceived(sharedBuffer, m_bufferedDataEncodedDataLength); > > Why not: > bool shouldFilter = m_contentFilter .... <<ETC>> > > > Source/WebKit/UIProcess/Network/NetworkProcessProxy.cpp:614 > > + if (!page) > > I'd just do: > > if (auto* page = ... > page->reload.... I have addressed these issues in the latest patch. Thanks for reviewing!
Per Arne Vollan
Comment 33 2022-02-18 16:57:48 PST
Per Arne Vollan
Comment 34 2022-02-18 17:02:34 PST
Note You need to log in before you can comment on or make changes to this bug.