Title: [215197] trunk
Revision
215197
Author
[email protected]
Date
2017-04-10 12:53:49 -0700 (Mon, 10 Apr 2017)

Log Message

[WK2][macOS] Block access to Apple Events before launch.
https://bugs.webkit.org/show_bug.cgi?id=170626
<rdar://problem/16079334>

Reviewed by Alexey Proskuryakov.

Source/WebKit2:

Clear the environment of the AppleEvent server name before initializing
AppKit so we never bother connecting.

* Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
(main):

Tools:

Add a new TestWebKitAPI test that fails if Apple Events are sent.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new files.
* TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent.cpp: Added.
(TestWebKitAPI::didReceiveMessageFromInjectedBundle):
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::TEST):
* TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent_Bundle.cpp: Added.
(TestWebKitAPI::InjectedBundleAppleEventTest::InjectedBundleAppleEventTest):
(TestWebKitAPI::InjectedBundleAppleEventTest::didCreatePage):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (215196 => 215197)


--- trunk/Source/WebKit2/ChangeLog	2017-04-10 19:38:44 UTC (rev 215196)
+++ trunk/Source/WebKit2/ChangeLog	2017-04-10 19:53:49 UTC (rev 215197)
@@ -1,3 +1,17 @@
+2017-04-10  Brent Fulgham  <[email protected]>
+
+        [WK2][macOS] Block access to Apple Events before launch.
+        https://bugs.webkit.org/show_bug.cgi?id=170626
+        <rdar://problem/16079334>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Clear the environment of the AppleEvent server name before initializing
+        AppKit so we never bother connecting.
+
+        * Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm:
+        (main):
+
 2017-04-10  Adrian Perez de Castro  <[email protected]>
 
         [GTK] Misplaced right click menu on web page due to deprecated gtk_menu_popup()

Modified: trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm (215196 => 215197)


--- trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2017-04-10 19:38:44 UTC (rev 215196)
+++ trunk/Source/WebKit2/Shared/EntryPointUtilities/mac/XPCService/XPCServiceMain.mm	2017-04-10 19:53:49 UTC (rev 215197)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2013, 2015, 2016 Apple Inc. All rights reserved.
+ * Copyright (C) 2013-2017 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -140,6 +140,11 @@
         }
     }
 
+#if PLATFORM(MAC)
+    // Don't allow Apple Events in WebKit processes. This can be removed when <rdar://problem/14012823> is fixed.
+    setenv("__APPLEEVENTSSERVICENAME", "", 1);
+#endif
+
     xpc_main(XPCServiceEventHandler);
     return 0;
 }

Modified: trunk/Tools/ChangeLog (215196 => 215197)


--- trunk/Tools/ChangeLog	2017-04-10 19:38:44 UTC (rev 215196)
+++ trunk/Tools/ChangeLog	2017-04-10 19:53:49 UTC (rev 215197)
@@ -1,3 +1,22 @@
+2017-04-10  Brent Fulgham  <[email protected]>
+
+        [WK2][macOS] Block access to Apple Events before launch.
+        https://bugs.webkit.org/show_bug.cgi?id=170626
+        <rdar://problem/16079334>
+
+        Reviewed by Alexey Proskuryakov.
+
+        Add a new TestWebKitAPI test that fails if Apple Events are sent.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: Add new files.
+        * TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent.cpp: Added.
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle):
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::TEST):
+        * TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent_Bundle.cpp: Added.
+        (TestWebKitAPI::InjectedBundleAppleEventTest::InjectedBundleAppleEventTest):
+        (TestWebKitAPI::InjectedBundleAppleEventTest::didCreatePage):
+
 2017-04-10  Guillaume Emont  <[email protected]>
 
         [JSC] Do not run FTL stress tests on MIPS

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (215196 => 215197)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-04-10 19:38:44 UTC (rev 215196)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2017-04-10 19:53:49 UTC (rev 215197)
@@ -214,6 +214,8 @@
 		7A909A811D877480007E10F8 /* IntPoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A731D877475007E10F8 /* IntPoint.cpp */; };
 		7A909A821D877480007E10F8 /* IntRect.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A741D877475007E10F8 /* IntRect.cpp */; };
 		7A909A831D877480007E10F8 /* IntSize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A909A751D877475007E10F8 /* IntSize.cpp */; };
+		7A95BDE11E9BEC5F00865498 /* InjectedBundleAppleEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A95BDE01E9BEC4000865498 /* InjectedBundleAppleEvent.cpp */; };
+		7A95BDE21E9BEC7400865498 /* InjectedBundleAppleEvent_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7A95BDDF1E9BEC4000865498 /* InjectedBundleAppleEvent_Bundle.cpp */; };
 		7AD3FE8E1D76131200B169A4 /* TransformationMatrix.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7AD3FE8D1D75FB8D00B169A4 /* TransformationMatrix.cpp */; };
 		7AE9E5091AE5AE8B00CF874B /* test.pdf in Copy Resources */ = {isa = PBXBuildFile; fileRef = 7AE9E5081AE5AE8B00CF874B /* test.pdf */; };
 		7AEAD47F1E20116C00416EFE /* CrossPartitionFileSchemeAccess.mm in Sources */ = {isa = PBXBuildFile; fileRef = 7AEAD47C1E20113800416EFE /* CrossPartitionFileSchemeAccess.mm */; };
@@ -1140,6 +1142,8 @@
 		7A909A731D877475007E10F8 /* IntPoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntPoint.cpp; sourceTree = "<group>"; };
 		7A909A741D877475007E10F8 /* IntRect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntRect.cpp; sourceTree = "<group>"; };
 		7A909A751D877475007E10F8 /* IntSize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IntSize.cpp; sourceTree = "<group>"; };
+		7A95BDDF1E9BEC4000865498 /* InjectedBundleAppleEvent_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleAppleEvent_Bundle.cpp; sourceTree = "<group>"; };
+		7A95BDE01E9BEC4000865498 /* InjectedBundleAppleEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundleAppleEvent.cpp; sourceTree = "<group>"; };
 		7A99D9931AD4A29D00373141 /* MenuTypesForMouseEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MenuTypesForMouseEvents.mm; sourceTree = "<group>"; };
 		7AA021BA1AB09EA70052953F /* DateMath.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DateMath.cpp; sourceTree = "<group>"; };
 		7AA6A1511AAC0B31002B2ED3 /* WorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WorkQueue.cpp; sourceTree = "<group>"; };
@@ -2370,6 +2374,8 @@
 		C0C5D3BB14598B6F00A802A6 /* mac */ = {
 			isa = PBXGroup;
 			children = (
+				7A95BDDF1E9BEC4000865498 /* InjectedBundleAppleEvent_Bundle.cpp */,
+				7A95BDE01E9BEC4000865498 /* InjectedBundleAppleEvent.cpp */,
 				9BD423991E04BD9800200395 /* AttributedSubstringForProposedRangeWithImage.mm */,
 				8349D3C11DB96DDA004A9F65 /* ContextMenuDownload.mm */,
 				BCAA485714A044D40088FAC4 /* EditorCommands.mm */,
@@ -2798,6 +2804,7 @@
 				7CCE7EC11A411A7E00447C4C /* HTMLCollectionNamedItem.mm in Sources */,
 				7CCE7EC21A411A7E00447C4C /* HTMLFormCollectionNamedItem.mm in Sources */,
 				7C83E0501D0A641800FEBCF3 /* HTMLParserIdioms.cpp in Sources */,
+				7A95BDE11E9BEC5F00865498 /* InjectedBundleAppleEvent.cpp in Sources */,
 				510477781D29923B009747EB /* IDBDeleteRecovery.mm in Sources */,
 				5110FCFA1E01CDB8006F8D0B /* IDBIndexUpgradeToV2.mm in Sources */,
 				51A587861D273AA9004BA9AF /* IndexedDBDatabaseProcessKill.mm in Sources */,
@@ -3039,6 +3046,7 @@
 				93F7E86F14DC8E5C00C84A99 /* NewFirstVisuallyNonEmptyLayoutFrames_Bundle.cpp in Sources */,
 				52E5CE4914D21EAB003B2BD8 /* ParentFrame_Bundle.cpp in Sources */,
 				C54237F116B8957D00E638FC /* PasteboardNotifications_Bundle.cpp in Sources */,
+				7A95BDE21E9BEC7400865498 /* InjectedBundleAppleEvent_Bundle.cpp in Sources */,
 				BC575BD9126F58E2006F0F12 /* PlatformUtilities.cpp in Sources */,
 				0F139E791A42457000F590F5 /* PlatformUtilitiesCocoa.mm in Sources */,
 				BC575BE0126F590D006F0F12 /* PlatformUtilitiesMac.mm in Sources */,

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent.cpp (0 => 215197)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent.cpp	2017-04-10 19:53:49 UTC (rev 215197)
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+#include <WebKit/WKRetainPtr.h>
+#include <cmath>
+
+namespace TestWebKitAPI {
+
+static bool done;
+static bool loadDone;
+static bool messageReceived;
+
+static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void* clientInfo)
+{
+    messageReceived = true;
+
+    EXPECT_WK_STREQ("DidAttemptToSendAppleEvent", messageName);
+    ASSERT_NOT_NULL(messageBody);
+    EXPECT_EQ(WKDoubleGetTypeID(), WKGetTypeID(messageBody));
+
+    WKDoubleRef returnCodeMessage = static_cast<WKDoubleRef>(messageBody);
+    double returnCode = WKDoubleGetValue(returnCodeMessage);
+    EXPECT_TRUE(std::isfinite(returnCode));
+
+    // Zero return code indicates the WebProcess successfully issued an Apple Event.
+    EXPECT_NE(0, returnCode);
+
+    if (loadDone)
+        done = true;
+}
+
+static void didFinishLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
+{
+    loadDone = true;
+    if (messageReceived)
+        done = true;
+}
+
+TEST(WebKit2, InjectedBundleAppleEvent)
+{
+    WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("InjectedBundleAppleEventTest"));
+
+    WKContextInjectedBundleClientV0 injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+
+    injectedBundleClient.base.version = 0;
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+
+    WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);
+
+    PlatformWebView webView(context.get());
+
+    WKPageLoaderClientV0 loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+
+    loaderClient.base.version = 0;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient.base);
+
+    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
+    WKPageLoadURL(webView.page(), url.get());
+
+    Util::run(&done);
+}
+
+} // namespace TestWebKitAPI
+
+#endif

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent_Bundle.cpp (0 => 215197)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/mac/InjectedBundleAppleEvent_Bundle.cpp	2017-04-10 19:53:49 UTC (rev 215197)
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+
+#if WK_HAVE_C_SPI
+
+#include "InjectedBundleTest.h"
+#include "PlatformUtilities.h"
+#include <Carbon/Carbon.h> // Needed for AppleEvents
+#include <WebKit/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+class InjectedBundleAppleEventTest : public InjectedBundleTest {
+public:
+    InjectedBundleAppleEventTest(const std::string& identifier)
+        : InjectedBundleTest(identifier)
+    {
+    }
+
+    virtual void didCreatePage(WKBundleRef bundle, WKBundlePageRef page)
+    {
+        FourCharCode appAddress = 'lgnw';
+        const char* eventFormat = "'----':TEXT(@)";
+        AppleEvent event;
+
+        OSStatus rc = AEBuildAppleEvent('syso', 'gurl', 'sign', &appAddress, sizeof(appAddress), kAutoGenerateReturnID, 0, &event, nullptr, eventFormat, "file:///does-not-exist.html");
+        assert(!rc);
+
+        rc = AESendMessage(&event, nullptr, -1, 0);
+
+        WKRetainPtr<WKDoubleRef> returnCode = adoptWK(WKDoubleCreate(rc));
+        WKBundlePostMessage(bundle, Util::toWK("DidAttemptToSendAppleEvent").get(), returnCode.get());
+    }
+};
+
+static InjectedBundleTest::Register<InjectedBundleAppleEventTest> registrar("InjectedBundleAppleEventTest");
+
+} // namespace TestWebKitAPI
+
+#endif
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to