Title: [271469] trunk/Source/WebKit
Revision
271469
Author
pvol...@apple.com
Date
2021-01-13 15:27:18 -0800 (Wed, 13 Jan 2021)

Log Message

[Cocoa] Network extension sandbox extensions are sometimes issued too late
https://bugs.webkit.org/show_bug.cgi?id=220525
<rdar://problem/68443565>

Reviewed by Brent Fulgham.

Currently, Network extension sandbox extensions are sent to the WebContent process as part of the load parameters, but this is too late in some cases.
In these cases, the extensions can be sent along with the DidReceivePolicyDecision message.

* Shared/Cocoa/LoadParametersCocoa.mm:
(WebKit::LoadParameters::platformEncode const):
(WebKit::LoadParameters::platformDecode):
* Shared/LoadParameters.h:
* UIProcess/Cocoa/WebPageProxyCocoa.mm:
(WebKit::WebPageProxy::addPlatformLoadParameters):
* UIProcess/WebPageProxy.cpp:
(WebKit::createNetworkExtensionsSandboxExtensions):
(WebKit::WebPageProxy::decidePolicyForNavigationActionAsyncShared):
(WebKit::WebPageProxy::decidePolicyForNewWindowAction):
(WebKit::WebPageProxy::decidePolicyForResponseShared):
* WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
(WebKit::WebPage::platformDidReceiveLoadParameters):
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::didReceivePolicyDecision):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (271468 => 271469)


--- trunk/Source/WebKit/ChangeLog	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/ChangeLog	2021-01-13 23:27:18 UTC (rev 271469)
@@ -1,3 +1,32 @@
+2021-01-13  Per Arne Vollan  <pvol...@apple.com>
+
+        [Cocoa] Network extension sandbox extensions are sometimes issued too late
+        https://bugs.webkit.org/show_bug.cgi?id=220525
+        <rdar://problem/68443565>
+
+        Reviewed by Brent Fulgham.
+
+        Currently, Network extension sandbox extensions are sent to the WebContent process as part of the load parameters, but this is too late in some cases.
+        In these cases, the extensions can be sent along with the DidReceivePolicyDecision message.
+
+        * Shared/Cocoa/LoadParametersCocoa.mm:
+        (WebKit::LoadParameters::platformEncode const):
+        (WebKit::LoadParameters::platformDecode):
+        * Shared/LoadParameters.h:
+        * UIProcess/Cocoa/WebPageProxyCocoa.mm:
+        (WebKit::WebPageProxy::addPlatformLoadParameters):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::createNetworkExtensionsSandboxExtensions):
+        (WebKit::WebPageProxy::decidePolicyForNavigationActionAsyncShared):
+        (WebKit::WebPageProxy::decidePolicyForNewWindowAction):
+        (WebKit::WebPageProxy::decidePolicyForResponseShared):
+        * WebProcess/WebPage/Cocoa/WebPageCocoa.mm:
+        (WebKit::WebPage::platformDidReceiveLoadParameters):
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::didReceivePolicyDecision):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2021-01-13  Jiewen Tan  <jiewen_...@apple.com>
 
         Crash at SOAuthorizationSession::dismissViewController

Modified: trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm (271468 => 271469)


--- trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/Shared/Cocoa/LoadParametersCocoa.mm	2021-01-13 23:27:18 UTC (rev 271469)
@@ -37,8 +37,6 @@
 {
     IPC::encode(encoder, dataDetectionContext.get());
 
-    encoder << neHelperExtensionHandle;
-    encoder << neSessionManagerExtensionHandle;
 #if PLATFORM(IOS)
     encoder << contentFilterExtensionHandle;
     encoder << frontboardServiceExtensionHandle;
@@ -50,18 +48,6 @@
     if (!IPC::decode(decoder, parameters.dataDetectionContext))
         return false;
 
-    Optional<Optional<SandboxExtension::Handle>> neHelperExtensionHandle;
-    decoder >> neHelperExtensionHandle;
-    if (!neHelperExtensionHandle)
-        return false;
-    parameters.neHelperExtensionHandle = WTFMove(*neHelperExtensionHandle);
-
-    Optional<Optional<SandboxExtension::Handle>> neSessionManagerExtensionHandle;
-    decoder >> neSessionManagerExtensionHandle;
-    if (!neSessionManagerExtensionHandle)
-        return false;
-    parameters.neSessionManagerExtensionHandle = WTFMove(*neSessionManagerExtensionHandle);
-
 #if PLATFORM(IOS)
     Optional<Optional<SandboxExtension::Handle>> contentFilterExtensionHandle;
     decoder >> contentFilterExtensionHandle;

Modified: trunk/Source/WebKit/Shared/LoadParameters.h (271468 => 271469)


--- trunk/Source/WebKit/Shared/LoadParameters.h	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/Shared/LoadParameters.h	2021-01-13 23:27:18 UTC (rev 271469)
@@ -74,8 +74,6 @@
 
 #if PLATFORM(COCOA)
     RetainPtr<NSDictionary> dataDetectionContext;
-    Optional<SandboxExtension::Handle> neHelperExtensionHandle;
-    Optional<SandboxExtension::Handle> neSessionManagerExtensionHandle;
 #endif
 #if PLATFORM(IOS)
     Optional<SandboxExtension::Handle> contentFilterExtensionHandle;

Modified: trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm (271468 => 271469)


--- trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/UIProcess/Cocoa/WebPageProxyCocoa.mm	2021-01-13 23:27:18 UTC (rev 271469)
@@ -154,23 +154,6 @@
 {
     loadParameters.dataDetectionContext = m_uiClient->dataDetectionContext();
 
-#if ENABLE(CONTENT_FILTERING)
-    if (!process.hasNetworkExtensionSandboxAccess() && NetworkExtensionContentFilter::isRequired()) {
-        SandboxExtension::Handle helperHandle;
-        SandboxExtension::createHandleForMachLookup("com.apple.nehelper"_s, WTF::nullopt, helperHandle);
-        loadParameters.neHelperExtensionHandle = WTFMove(helperHandle);
-        SandboxExtension::Handle managerHandle;
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
-        SandboxExtension::createHandleForMachLookup("com.apple.nesessionmanager"_s, WTF::nullopt, managerHandle);
-#else
-        SandboxExtension::createHandleForMachLookup("com.apple.nesessionmanager.content-filter"_s, WTF::nullopt, managerHandle);
-#endif
-        loadParameters.neSessionManagerExtensionHandle = WTFMove(managerHandle);
-
-        process.markHasNetworkExtensionSandboxAccess();
-    }
-#endif
-
 #if PLATFORM(IOS)
     if (!process.hasManagedSessionSandboxAccess() && [getWebFilterEvaluatorClass() isManagedSession]) {
         SandboxExtension::Handle handle;
@@ -552,8 +535,24 @@
 
     send(Messages::WebPage::CreateAppHighlightInSelectedRange(createNewGroup));
 }
+#endif
 
+SandboxExtension::HandleArray WebPageProxy::createNetworkExtensionsSandboxExtensions(WebProcessProxy& process)
+{
+#if ENABLE(CONTENT_FILTERING)
+    if (!process.hasNetworkExtensionSandboxAccess() && NetworkExtensionContentFilter::isRequired()) {
+        process.markHasNetworkExtensionSandboxAccess();
+        constexpr ASCIILiteral neHelperService { "com.apple.nehelper"_s };
+#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500
+        constexpr ASCIILiteral neSessionManagerService { "com.apple.nesessionmanager"_s };
+#else
+        constexpr ASCIILiteral neSessionManagerService { "com.apple.nesessionmanager.content-filter"_s };
 #endif
+        return SandboxExtension::createHandlesForMachLookup({ neHelperService, neSessionManagerService }, WTF::nullopt);
+    }
+#endif
+    return SandboxExtension::HandleArray();
+}
 
 } // namespace WebKit
 

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.cpp (271468 => 271469)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.cpp	2021-01-13 23:27:18 UTC (rev 271469)
@@ -5027,7 +5027,7 @@
     MESSAGE_CHECK(process, frame);
 
     auto sender = PolicyDecisionSender::create(identifier, [webPageID, frameID, listenerID, process] (const auto& policyDecision) {
-        process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision), webPageID);
+        process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision, createNetworkExtensionsSandboxExtensions(process)), webPageID);
     });
 
     decidePolicyForNavigationAction(process.copyRef(), *frame, WTFMove(frameInfo), navigationID, WTFMove(navigationActionData), WTFMove(originatingFrameInfo), originatingPageID,
@@ -5338,7 +5338,7 @@
         ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);
 
         auto sender = PolicyDecisionSender::create(identifier, [this, protectedThis = WTFMove(protectedThis), frameID, listenerID] (const auto& policyDecision) {
-            send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision));
+            send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision, createNetworkExtensionsSandboxExtensions(m_process)));
         });
 
         receivedPolicyDecision(policyAction, nullptr, nullptr, WTFMove(navigationAction), WTFMove(sender));
@@ -5377,7 +5377,7 @@
         ASSERT_UNUSED(safeBrowsingWarning, !safeBrowsingWarning);
 
         auto sender = PolicyDecisionSender::create(identifier, [webPageID, frameID, listenerID, process = WTFMove(process)] (const auto& policyDecision) {
-            process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision), webPageID);
+            process->send(Messages::WebPage::DidReceivePolicyDecision(frameID, listenerID, policyDecision, createNetworkExtensionsSandboxExtensions(process)), webPageID);
         });
         
         receivedPolicyDecision(policyAction, navigation.get(), nullptr, WTFMove(navigationResponse), WTFMove(sender));
@@ -10339,6 +10339,13 @@
 
 #endif
 
+#if !PLATFORM(COCOA)
+SandboxExtension::HandleArray WebPageProxy::createNetworkExtensionsSandboxExtensions(WebProcessProxy& process)
+{
+    return SandboxExtension::HandleArray();
+}
+#endif
+
 } // namespace WebKit
 
 #undef RELEASE_LOG_IF_ALLOWED

Modified: trunk/Source/WebKit/UIProcess/WebPageProxy.h (271468 => 271469)


--- trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/UIProcess/WebPageProxy.h	2021-01-13 23:27:18 UTC (rev 271469)
@@ -2370,6 +2370,8 @@
     bool setIsNavigatingToAppBoundDomainAndCheckIfPermitted(bool isMainFrame, const URL&, Optional<NavigatingToAppBoundDomain>);
 #endif
 
+    static SandboxExtension::HandleArray createNetworkExtensionsSandboxExtensions(WebProcessProxy&);
+
     const Identifier m_identifier;
     WebCore::PageIdentifier m_webPageID;
     WeakPtr<PageClient> m_pageClient;

Modified: trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm (271468 => 271469)


--- trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/WebProcess/WebPage/Cocoa/WebPageCocoa.mm	2021-01-13 23:27:18 UTC (rev 271469)
@@ -81,14 +81,6 @@
 
     m_dataDetectionContext = parameters.dataDetectionContext;
 
-#if ENABLE(CONTENT_FILTERING)
-    if (parameters.neHelperExtensionHandle)
-        SandboxExtension::consumePermanently(*parameters.neHelperExtensionHandle);
-    if (parameters.neSessionManagerExtensionHandle)
-        SandboxExtension::consumePermanently(*parameters.neSessionManagerExtensionHandle);
-    NetworkExtensionContentFilter::setHasConsumedSandboxExtensions(parameters.neHelperExtensionHandle.hasValue() && parameters.neSessionManagerExtensionHandle.hasValue());
-#endif
-
 #if PLATFORM(IOS)
     if (parameters.contentFilterExtensionHandle)
         SandboxExtension::consumePermanently(*parameters.contentFilterExtensionHandle);
@@ -414,6 +406,16 @@
     postLayoutData.baseWritingDirection = frame.editor().baseWritingDirectionForSelectionStart();
 }
 
+void WebPage::consumeNetworkExtensionSandboxExtensions(const SandboxExtension::HandleArray& networkExtensionsHandles)
+{
+#if ENABLE(CONTENT_FILTERING)
+    SandboxExtension::consumePermanently(networkExtensionsHandles);
+    NetworkExtensionContentFilter::setHasConsumedSandboxExtensions(networkExtensionsHandles.size());
+#else
+    UNUSED_PARAM(networkExtensionsHandles);
+#endif
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(COCOA)

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp (271468 => 271469)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2021-01-13 23:27:18 UTC (rev 271469)
@@ -3363,8 +3363,10 @@
         pluginView->setLayerHostingMode(m_layerHostingMode);
 }
 
-void WebPage::didReceivePolicyDecision(FrameIdentifier frameID, uint64_t listenerID, PolicyDecision&& policyDecision)
+void WebPage::didReceivePolicyDecision(FrameIdentifier frameID, uint64_t listenerID, PolicyDecision&& policyDecision, const SandboxExtension::HandleArray& networkExtensionsHandles)
 {
+    consumeNetworkExtensionSandboxExtensions(networkExtensionsHandles);
+
     WebFrame* frame = WebProcess::singleton().webFrame(frameID);
     RELEASE_LOG_IF_ALLOWED(Loading, "didReceivePolicyDecision: policyAction: %u - frameID: %llu - webFrame: %p - mainFrame: %d", (unsigned)policyDecision.policyAction, frameID.toUInt64(), frame, frame ? frame->isMainFrame() : 0);
 
@@ -7149,6 +7151,11 @@
 }
 #endif
 
+#if !PLATFORM(COCOA)
+void WebPage::consumeNetworkExtensionSandboxExtensions(const SandboxExtension::HandleArray&)
+{
+}
+#endif
 
 } // namespace WebKit
 

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.h (271468 => 271469)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.h	2021-01-13 23:27:18 UTC (rev 271469)
@@ -1584,7 +1584,7 @@
     void clearServiceWorkerEntitlementOverride(CompletionHandler<void()>&& completionHandler) { completionHandler(); }
 #endif
 
-    void didReceivePolicyDecision(WebCore::FrameIdentifier, uint64_t listenerID, PolicyDecision&&);
+    void didReceivePolicyDecision(WebCore::FrameIdentifier, uint64_t listenerID, PolicyDecision&&, const SandboxExtension::HandleArray&);
     void continueWillSubmitForm(WebCore::FrameIdentifier, uint64_t listenerID);
     void setUserAgent(const String&);
     void setCustomTextEncodingName(const String&);
@@ -1801,6 +1801,8 @@
 
     void setSelectionRange(const WebCore::IntPoint&, WebCore::TextGranularity, bool);
     
+    void consumeNetworkExtensionSandboxExtensions(const SandboxExtension::HandleArray&);
+
     WebCore::PageIdentifier m_identifier;
 
     std::unique_ptr<WebCore::Page> m_page;

Modified: trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in (271468 => 271469)


--- trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-01-13 23:20:21 UTC (rev 271468)
+++ trunk/Source/WebKit/WebProcess/WebPage/WebPage.messages.in	2021-01-13 23:27:18 UTC (rev 271469)
@@ -196,7 +196,7 @@
 
     UpdateWebsitePolicies(struct WebKit::WebsitePoliciesData websitePolicies)
     NotifyUserScripts()
-    DidReceivePolicyDecision(WebCore::FrameIdentifier frameID, uint64_t listenerID, struct WebKit::PolicyDecision policyDecision)
+    DidReceivePolicyDecision(WebCore::FrameIdentifier frameID, uint64_t listenerID, struct WebKit::PolicyDecision policyDecision, WebKit::SandboxExtension::HandleArray networkExtensionsSandboxExtensions)
 
     ContinueWillSubmitForm(WebCore::FrameIdentifier frameID, uint64_t listenerID)
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to