Title: [228835] branches/safari-605-branch

Diff

Modified: branches/safari-605-branch/Source/WebKit/ChangeLog (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/ChangeLog	2018-02-20 22:29:56 UTC (rev 228835)
@@ -1,3 +1,42 @@
+2018-02-20  Jason Marcell  <[email protected]>
+
+        Cherry-pick r228589. rdar://problem/37697687
+
+    2018-02-16  Ryosuke Niwa  <[email protected]>
+
+            Add an entitlement check for service worker on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=182865
+            <rdar://problem/37505903>
+
+            Reviewed by Brady Eidson.
+
+            Added an entitlement check to enable service workers on iOS.
+
+            * Shared/mac/SandboxUtilities.h:
+            * Shared/mac/SandboxUtilities.mm:
+            (WebKit::connectedProcessHasEntitlement): Added.
+            * StorageProcess/StorageProcess.cpp:
+            (WebKit::StorageProcess::createStorageToWebProcessConnection): Enforce the entitlement check by crashing
+            when this code is executed without the parent process having the service worker entitlement. This should
+            never happen unless someone is trying to bypass the entitlement check in UI Process since we ordinarily
+            disable service worker gracefully in WKWebView _initializeWithConfiguration.
+            (WebKit::StorageProcess::swServerForSession): Ditto.
+            (WebKit::StorageProcess::registerSWServerConnection): Ditto.
+            * StorageProcess/StorageProcess.h:
+            (WebKit::StorageProcess::parentProcessHasServiceWorkerEntitlement const): Added.
+            * StorageProcess/ios/StorageProcessIOS.mm:
+            (WebKit::StorageProcess::parentProcessHasServiceWorkerEntitlement const): Added.
+            * UIProcess/API/Cocoa/WKWebView.mm:
+            (-[WKWebView _initializeWithConfiguration:]): Disable the service workers when the entitlement is
+            missing from the current process. The entitlement is enforced by WebContent and Storage process.
+            This check avoids crashing WebContent process and gracefully disabling the feature.
+            * WebProcess/WebPage/WebPage.cpp:
+            (WebKit::WebPage::updatePreferences): Enforce the entitlement check.
+            * WebProcess/WebPage/WebPage.h:
+            (WebKit::WebPage::parentProcessHasServiceWorkerEntitlement const): Added.
+            * WebProcess/WebPage/ios/WebPageIOS.mm:
+            (WebKit::WebPage::parentProcessHasServiceWorkerEntitlement const): Added.
+
 2018-02-19  Jason Marcell  <[email protected]>
 
         Cherry-pick r228564. rdar://problem/37675352

Modified: branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.h (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.h	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.h	2018-02-20 22:29:56 UTC (rev 228835)
@@ -39,5 +39,6 @@
 String pathForProcessContainer();
 
 bool processHasEntitlement(NSString *entitlement);
+bool connectedProcessHasEntitlement(xpc_connection_t, NSString *entitlement);
 
 }

Modified: branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.mm (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.mm	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/Shared/mac/SandboxUtilities.mm	2018-02-20 22:29:56 UTC (rev 228835)
@@ -92,4 +92,20 @@
     return CFBooleanGetValue(static_cast<CFBooleanRef>(value.get()));
 }
 
+bool connectedProcessHasEntitlement(xpc_connection_t connection, NSString *entitlement)
+{
+    audit_token_t token;
+    xpc_connection_get_audit_token(connection, &token);
+    auto task = adoptCF(SecTaskCreateWithAuditToken(NULL, token));
+
+    auto value = adoptCF(SecTaskCopyValueForEntitlement(task.get(), (__bridge CFStringRef)entitlement, nullptr));
+    if (!value)
+        return false;
+
+    if (CFGetTypeID(value.get()) != CFBooleanGetTypeID())
+        return false;
+
+    return CFBooleanGetValue(static_cast<CFBooleanRef>(value.get()));
 }
+
+}

Modified: branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.cpp (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.cpp	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.cpp	2018-02-20 22:29:56 UTC (rev 228835)
@@ -254,6 +254,7 @@
 
 #if ENABLE(SERVICE_WORKER)
     if (isServiceWorkerProcess && !m_storageToWebProcessConnections.isEmpty()) {
+        RELEASE_ASSERT(parentProcessHasServiceWorkerEntitlement());
         ASSERT(m_waitingForServerToContextProcessConnection);
         m_serverToContextConnection = WebSWServerToContextConnection::create(m_storageToWebProcessConnections.last()->connection());
         m_waitingForServerToContextProcessConnection = false;
@@ -404,6 +405,7 @@
 #if ENABLE(SERVICE_WORKER)
 SWServer& StorageProcess::swServerForSession(PAL::SessionID sessionID)
 {
+    RELEASE_ASSERT(parentProcessHasServiceWorkerEntitlement());
     ASSERT(sessionID.isValid());
     auto result = m_swServers.add(sessionID, nullptr);
     if (!result.isNewEntry) {
@@ -492,6 +494,7 @@
 
 void StorageProcess::registerSWServerConnection(WebSWServerConnection& connection)
 {
+    RELEASE_ASSERT(parentProcessHasServiceWorkerEntitlement());
     ASSERT(!m_swServerConnections.contains(connection.identifier()));
     m_swServerConnections.add(connection.identifier(), &connection);
     swOriginStoreForSession(connection.sessionID()).registerSWServerConnection(connection);

Modified: branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.h (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.h	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/StorageProcess/StorageProcess.h	2018-02-20 22:29:56 UTC (rev 228835)
@@ -86,6 +86,12 @@
     void getSandboxExtensionsForBlobFiles(const Vector<String>& filenames, WTF::Function<void (SandboxExtension::HandleArray&&)>&& completionHandler);
 #endif
 
+#if PLATFORM(IOS)
+    bool parentProcessHasServiceWorkerEntitlement() const;
+#else
+    bool parentProcessHasServiceWorkerEntitlement() const { return true; }
+#endif
+
 #if ENABLE(SERVICE_WORKER)
     // For now we just have one global connection to service worker context processes.
     // This will change in the future.

Modified: branches/safari-605-branch/Source/WebKit/StorageProcess/ios/StorageProcessIOS.mm (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/StorageProcess/ios/StorageProcessIOS.mm	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/StorageProcess/ios/StorageProcessIOS.mm	2018-02-20 22:29:56 UTC (rev 228835)
@@ -30,6 +30,7 @@
 #import "StorageProcess.h"
 
 #import "SandboxInitializationParameters.h"
+#import "SandboxUtilities.h"
 #import <WebCore/FileSystem.h>
 #import <WebCore/LocalizedStrings.h>
 #import <WebCore/NotImplemented.h>
@@ -58,6 +59,12 @@
 #endif
 }
 
+bool StorageProcess::parentProcessHasServiceWorkerEntitlement() const
+{
+    static bool hasEntitlement = connectedProcessHasEntitlement(parentProcessConnection()->xpcConnection(), @"com.apple.developer.WebKit.ServiceWorkers");
+    return hasEntitlement;
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)

Modified: branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm	2018-02-20 22:29:56 UTC (rev 228835)
@@ -44,6 +44,7 @@
 #import "RemoteLayerTreeTransaction.h"
 #import "RemoteObjectRegistry.h"
 #import "RemoteObjectRegistryMessages.h"
+#import "SandboxUtilities.h"
 #import "UIDelegate.h"
 #import "VersionChecks.h"
 #import "ViewGestureController.h"
@@ -606,6 +607,11 @@
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::legacyEncryptedMediaAPIEnabledKey(), WebKit::WebPreferencesStore::Value(!![_configuration _legacyEncryptedMediaAPIEnabled]));
 #endif
 
+#if PLATFORM(IOS) && ENABLE(SERVICE_WORKER)
+    if (!WebKit::processHasEntitlement(@"com.apple.developer.WebKit.ServiceWorkers"))
+        pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::serviceWorkersEnabledKey(), WebKit::WebPreferencesStore::Value(false));
+#endif
+
 #if PLATFORM(IOS)
     CGRect bounds = self.bounds;
     _scrollView = adoptNS([[WKScrollView alloc] initWithFrame:bounds]);

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.cpp	2018-02-20 22:29:56 UTC (rev 228835)
@@ -3163,6 +3163,9 @@
 #endif
 #endif
 
+    if (store.getBoolValueForKey(WebPreferencesKey::serviceWorkersEnabledKey()))
+        RELEASE_ASSERT(parentProcessHasServiceWorkerEntitlement());
+
     if (m_drawingArea)
         m_drawingArea->updatePreferences(store);
 }

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.h (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/WebPage.h	2018-02-20 22:29:56 UTC (rev 228835)
@@ -1215,6 +1215,12 @@
     void updatePreferences(const WebPreferencesStore&);
     void updatePreferencesGenerated(const WebPreferencesStore&);
 
+#if PLATFORM(IOS)
+    bool parentProcessHasServiceWorkerEntitlement() const;
+#else
+    bool parentProcessHasServiceWorkerEntitlement() const { return true; }
+#endif
+
     void didReceivePolicyDecision(uint64_t frameID, uint64_t listenerID, WebCore::PolicyAction, uint64_t navigationID, const DownloadID&, std::optional<WebsitePoliciesData>&&);
     void continueWillSubmitForm(uint64_t frameID, uint64_t listenerID);
     void setUserAgent(const String&);

Modified: branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (228834 => 228835)


--- branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm	2018-02-20 22:29:56 UTC (rev 228835)
@@ -40,6 +40,7 @@
 #import "PluginView.h"
 #import "PrintInfo.h"
 #import "RemoteLayerTreeDrawingArea.h"
+#import "SandboxUtilities.h"
 #import "UserData.h"
 #import "VisibleContentRectUpdateInfo.h"
 #import "WKAccessibilityWebPageObjectIOS.h"
@@ -392,6 +393,12 @@
     return eventWasHandled;
 }
 
+bool WebPage::parentProcessHasServiceWorkerEntitlement() const
+{
+    static bool hasEntitlement = connectedProcessHasEntitlement(WebProcess::singleton().parentProcessConnection()->xpcConnection(), @"com.apple.developer.WebKit.ServiceWorkers");
+    return hasEntitlement;
+}
+
 void WebPage::sendComplexTextInputToPlugin(uint64_t, const String&)
 {
     notImplemented();

Modified: branches/safari-605-branch/Tools/ChangeLog (228834 => 228835)


--- branches/safari-605-branch/Tools/ChangeLog	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Tools/ChangeLog	2018-02-20 22:29:56 UTC (rev 228835)
@@ -1,3 +1,22 @@
+2018-02-20  Jason Marcell  <[email protected]>
+
+        Cherry-pick r228589. rdar://problem/37697687
+
+    2018-02-16  Ryosuke Niwa  <[email protected]>
+
+            Add an entitlement check for service worker on iOS
+            https://bugs.webkit.org/show_bug.cgi?id=182865
+            <rdar://problem/37505903>
+
+            Reviewed by Brady Eidson.
+
+            Added the service worker entitlements to WebKitTestRunner and TestWebKitAPI on iOS.
+
+            * TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements:
+            * WebKitTestRunner/Configurations/WebKitTestRunnerApp-iOS.entitlements:
+            * WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig:
+            * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj:
+
 2018-02-15  Jason Marcell  <[email protected]>
 
         Cherry-pick r228482. rdar://problem/37559826

Modified: branches/safari-605-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements (228834 => 228835)


--- branches/safari-605-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements	2018-02-20 22:29:56 UTC (rev 228835)
@@ -6,5 +6,7 @@
 	<array>
 		<string>com.apple.TestWebKitAPI</string>
 	</array>
+	<key>com.apple.developer.WebKit.ServiceWorkers</key>
+	<true/>
 </dict>
 </plist>

Copied: branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp-iOS.entitlements (from rev 228834, branches/safari-605-branch/Tools/TestWebKitAPI/Configurations/TestWebKitAPI-iOS.entitlements) (0 => 228835)


--- branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp-iOS.entitlements	                        (rev 0)
+++ branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp-iOS.entitlements	2018-02-20 22:29:56 UTC (rev 228835)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>com.apple.developer.WebKit.ServiceWorkers</key>
+    <true/>
+</dict>
+</plist>

Modified: branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig (228834 => 228835)


--- branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Tools/WebKitTestRunner/Configurations/WebKitTestRunnerApp.xcconfig	2018-02-20 22:29:56 UTC (rev 228835)
@@ -39,3 +39,5 @@
 EXCLUDED_SOURCE_FILE_NAMES[sdk=watch*] = ios/Launch.storyboard;
 
 TARGETED_DEVICE_FAMILY = 1,2;
+
+CODE_SIGN_ENTITLEMENTS[sdk=iphone*] = Configurations/WebKitTestRunnerApp-iOS.entitlements;

Modified: branches/safari-605-branch/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj (228834 => 228835)


--- branches/safari-605-branch/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj	2018-02-20 22:29:50 UTC (rev 228834)
+++ branches/safari-605-branch/Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj	2018-02-20 22:29:56 UTC (rev 228835)
@@ -313,6 +313,7 @@
 		841CC00D181185BF0042E9B6 /* Options.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Options.cpp; sourceTree = "<group>"; };
 		841CC00E181185BF0042E9B6 /* Options.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Options.h; sourceTree = "<group>"; };
 		8DD76FA10486AA7600D96B5E /* WebKitTestRunner */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = WebKitTestRunner; sourceTree = BUILT_PRODUCTS_DIR; };
+		9B0D132E2036D346008FC8FB /* WebKitTestRunnerApp-iOS.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = "WebKitTestRunnerApp-iOS.entitlements"; sourceTree = "<group>"; };
 		A18510271B9ADE4800744AEB /* libWebKitTestRunner.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libWebKitTestRunner.a; sourceTree = BUILT_PRODUCTS_DIR; };
 		A18510381B9ADF2200744AEB /* WebKitTestRunner.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitTestRunner.xcconfig; sourceTree = "<group>"; };
 		A18510391B9ADFF800744AEB /* WebKitTestRunnerApp.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = WebKitTestRunnerApp.xcconfig; sourceTree = "<group>"; };
@@ -752,6 +753,7 @@
 				BC793427118F7DAF005EA8E2 /* DebugRelease.xcconfig */,
 				BC25197111D15E61002EBC01 /* InjectedBundle.xcconfig */,
 				A18510381B9ADF2200744AEB /* WebKitTestRunner.xcconfig */,
+				9B0D132E2036D346008FC8FB /* WebKitTestRunnerApp-iOS.entitlements */,
 				A18510391B9ADFF800744AEB /* WebKitTestRunnerApp.xcconfig */,
 				BC251A1811D16795002EBC01 /* WebKitTestRunnerLibrary.xcconfig */,
 			);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to