Diff
Modified: trunk/Source/WebCore/ChangeLog (280013 => 280014)
--- trunk/Source/WebCore/ChangeLog 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Source/WebCore/ChangeLog 2021-07-17 01:00:19 UTC (rev 280014)
@@ -1,3 +1,22 @@
+2021-07-16 Alex Christensen <[email protected]>
+
+ Network access prevention SPI should prevent preconnecting, and it should first allow injected bundle to change request
+ https://bugs.webkit.org/show_bug.cgi?id=228044
+ <rdar://72995136>
+
+ Reviewed by Tim Horton.
+
+ WKWebViewConfiguration._loadsFromNetwork and its successor _allowedNetworkHosts have two issues:
+ 1. They allow link rel=preconnect to still preconnect to a host. While this doesn't reveal much information, it does reveal some.
+ 2. It blocks loads before giving the injected bundle a chance to change the scheme of the request. This SPI is relatively new and
+ intended to replace the injected bundle, but the user from this radar needs to have an injected bundle make changes first.
+
+ Both problems are fixed and covered by API tests.
+
+ * loader/ResourceLoadNotifier.cpp:
+ (WebCore::ResourceLoadNotifier::dispatchWillSendRequest):
+ * page/Page.h:
+
2021-07-16 Myles C. Maxfield <[email protected]>
Fix Apple internal build
Modified: trunk/Source/WebCore/loader/ResourceLoadNotifier.cpp (280013 => 280014)
--- trunk/Source/WebCore/loader/ResourceLoadNotifier.cpp 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Source/WebCore/loader/ResourceLoadNotifier.cpp 2021-07-17 01:00:19 UTC (rev 280014)
@@ -133,6 +133,10 @@
if (m_frame.loader().documentLoader())
m_frame.loader().documentLoader()->didTellClientAboutLoad(request.url().string());
+ // Notifying the FrameLoaderClient may cause the frame to be destroyed.
+ Ref<Frame> protectedFrame(m_frame);
+ m_frame.loader().client().dispatchWillSendRequest(loader, identifier, request, redirectResponse);
+
if (auto* page = m_frame.page()) {
if (!page->loadsSubresources()) {
if (!m_frame.isMainFrame() || (m_initialRequestIdentifier && *m_initialRequestIdentifier != identifier))
@@ -140,10 +144,6 @@
} else if (!page->allowsLoadFromURL(request.url()))
request = { };
}
-
- // Notifying the FrameLoaderClient may cause the frame to be destroyed.
- Ref<Frame> protect(m_frame);
- m_frame.loader().client().dispatchWillSendRequest(loader, identifier, request, redirectResponse);
// If the URL changed, then we want to put that new URL in the "did tell client" set too.
if (!request.isNull() && oldRequestURL != request.url().string() && m_frame.loader().documentLoader())
Modified: trunk/Source/WebCore/page/Page.h (280013 => 280014)
--- trunk/Source/WebCore/page/Page.h 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Source/WebCore/page/Page.h 2021-07-17 01:00:19 UTC (rev 280014)
@@ -814,7 +814,7 @@
bool isUtilityPage() const { return m_isUtilityPage; }
bool loadsSubresources() const { return m_loadsSubresources; }
- bool allowsLoadFromURL(const URL&) const;
+ WEBCORE_EXPORT bool allowsLoadFromURL(const URL&) const;
ShouldRelaxThirdPartyCookieBlocking shouldRelaxThirdPartyCookieBlocking() const { return m_shouldRelaxThirdPartyCookieBlocking; }
bool isLowPowerModeEnabled() const { return m_throttlingReasons.contains(ThrottlingReason::LowPowerMode); }
Modified: trunk/Source/WebKit/ChangeLog (280013 => 280014)
--- trunk/Source/WebKit/ChangeLog 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Source/WebKit/ChangeLog 2021-07-17 01:00:19 UTC (rev 280014)
@@ -1,3 +1,14 @@
+2021-07-16 Alex Christensen <[email protected]>
+
+ Network access prevention SPI should prevent preconnecting, and it should first allow injected bundle to change request
+ https://bugs.webkit.org/show_bug.cgi?id=228044
+ <rdar://72995136>
+
+ Reviewed by Tim Horton.
+
+ * WebProcess/Network/WebLoaderStrategy.cpp:
+ (WebKit::WebLoaderStrategy::preconnectTo):
+
2021-07-16 John Wilander <[email protected]>
PCM: Add early return when unlinkable token is used and add more happy path Web Inspector logging
Modified: trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp (280013 => 280014)
--- trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Source/WebKit/WebProcess/Network/WebLoaderStrategy.cpp 2021-07-17 01:00:19 UTC (rev 280014)
@@ -764,6 +764,12 @@
void WebLoaderStrategy::preconnectTo(WebCore::ResourceRequest&& request, WebPage& webPage, WebFrame& webFrame, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, PreconnectCompletionHandler&& completionHandler)
{
+ if (webPage.corePage() && !webPage.corePage()->allowsLoadFromURL(request.url())) {
+ if (completionHandler)
+ completionHandler({ });
+ return;
+ }
+
if (auto* document = webPage.mainFrame()->document()) {
request.setFirstPartyForCookies(document->firstPartyForCookies());
if (auto* loader = document->loader())
Modified: trunk/Tools/ChangeLog (280013 => 280014)
--- trunk/Tools/ChangeLog 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Tools/ChangeLog 2021-07-17 01:00:19 UTC (rev 280014)
@@ -1,3 +1,19 @@
+2021-07-16 Alex Christensen <[email protected]>
+
+ Network access prevention SPI should prevent preconnecting, and it should first allow injected bundle to change request
+ https://bugs.webkit.org/show_bug.cgi?id=228044
+ <rdar://72995136>
+
+ Reviewed by Tim Horton.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm:
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKitCocoa/SchemeChangingPlugIn.mm: Added.
+ (-[SchemeChangingPlugIn webProcessPlugIn:didCreateBrowserContextController:]):
+ (-[SchemeChangingPlugIn webProcessPlugInBrowserContextController:frame:willSendRequest:redirectResponse:]):
+ * TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm:
+
2021-07-16 Commit Queue <[email protected]>
Unreviewed, reverting r279916.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (280013 => 280014)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2021-07-17 01:00:19 UTC (rev 280014)
@@ -524,6 +524,7 @@
5CB5B3C21FFC55CF00C27BB0 /* FrameHandleSerialization.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB5B3BD1FFC517E00C27BB0 /* FrameHandleSerialization.mm */; };
5CB7AFDC23C4529700E49CF3 /* ResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CB7AFDB23C451E400E49CF3 /* ResourceLoadDelegate.mm */; };
5CBAA7FB2440EA0200564A8B /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CBAA7FA2440EA0200564A8B /* CFNetwork.framework */; };
+ 5CC8B20626A2535F00909603 /* SchemeChangingPlugIn.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CC8B16226A2527C00909603 /* SchemeChangingPlugIn.mm */; };
5CCB10E1213457D300AC5AF0 /* ResponsivenessTimer.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CCB10E02134579D00AC5AF0 /* ResponsivenessTimer.mm */; };
5CCB10E2213457D500AC5AF0 /* ResponsivenessTimerDoesntFireEarly.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CCB10DD2134579C00AC5AF0 /* ResponsivenessTimerDoesntFireEarly.mm */; };
5CCB10E3213457D800AC5AF0 /* RestoreSessionStateWithoutNavigation.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5CCB10DE2134579D00AC5AF0 /* RestoreSessionStateWithoutNavigation.mm */; };
@@ -2390,6 +2391,7 @@
5CBAA7F324327F6B00564A8B /* TestUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestUIDelegate.h; path = cocoa/TestUIDelegate.h; sourceTree = "<group>"; };
5CBAA7F424327F6B00564A8B /* TestUIDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestUIDelegate.mm; path = cocoa/TestUIDelegate.mm; sourceTree = "<group>"; };
5CBAA7FA2440EA0200564A8B /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; };
+ 5CC8B16226A2527C00909603 /* SchemeChangingPlugIn.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = SchemeChangingPlugIn.mm; sourceTree = "<group>"; };
5CCB10DD2134579C00AC5AF0 /* ResponsivenessTimerDoesntFireEarly.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ResponsivenessTimerDoesntFireEarly.mm; sourceTree = "<group>"; };
5CCB10DE2134579D00AC5AF0 /* RestoreSessionStateWithoutNavigation.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RestoreSessionStateWithoutNavigation.mm; sourceTree = "<group>"; };
5CCB10DF2134579D00AC5AF0 /* ShouldGoToBackForwardListItem.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ShouldGoToBackForwardListItem.mm; sourceTree = "<group>"; };
@@ -3588,6 +3590,7 @@
F4D2986D20FEE7370092D636 /* RunScriptAfterDocumentLoad.mm */,
5CA985512113CB8C0057EB6B /* SafeBrowsing.mm */,
95095F1F262FFFA50000D920 /* SampledPageTopColor.mm */,
+ 5CC8B16226A2527C00909603 /* SchemeChangingPlugIn.mm */,
CE0947362063223B003C9BA0 /* SchemeRegistry.mm */,
51EB12931FDF050500A5A1BD /* ServiceWorkerBasic.mm */,
5C683471235ACC7C0041E6B1 /* ServiceWorkerTCPServer.h */,
@@ -6006,6 +6009,7 @@
1A4F81CF1BDFFD53004E672E /* RemoteObjectRegistryPlugIn.mm in Sources */,
A12DDC021E837C2400CF6CAE /* RenderedImageWithOptionsPlugIn.mm in Sources */,
5245178721B9F57B0082CB34 /* RenderingProgressPlugIn.mm in Sources */,
+ 5CC8B20626A2535F00909603 /* SchemeChangingPlugIn.mm in Sources */,
DFB80E38261512C1002D4771 /* TestAwakener.mm in Sources */,
7C882E091C80C630006BF731 /* UserContentWorldPlugIn.mm in Sources */,
7C83E03D1D0A60D600FEBCF3 /* UtilitiesCocoa.mm in Sources */,
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm (280013 => 280014)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/Preconnect.mm 2021-07-17 01:00:19 UTC (rev 280014)
@@ -31,6 +31,7 @@
#import "TestUIDelegate.h"
#import "Utilities.h"
#import "WKWebViewConfigurationExtras.h"
+#import <WebKit/WKWebViewConfigurationPrivate.h>
#import <WebKit/WKWebViewPrivate.h>
#import <pal/spi/cf/CFNetworkSPI.h>
#import <wtf/RetainPtr.h>
@@ -231,4 +232,33 @@
#endif // HAVE(PRECONNECT_PING)
+TEST(Preconnect, DisablePreconnect)
+{
+ size_t connectionCount { 0 };
+ HTTPServer server([&](Connection) {
+ connectionCount++;
+ });
+ NSString *html = [NSString stringWithFormat:@"<link rel='preconnect' href=''>", server.port()];
+
+ {
+ auto configuration = adoptNS([WKWebViewConfiguration new]);
+ configuration.get()._allowedNetworkHosts = [NSSet set];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration.get()]);
+ [webView loadHTMLString:html baseURL:nil];
+ [webView _test_waitForDidFinishNavigation];
+ Util::spinRunLoop(10);
+ usleep(10000);
+ Util::spinRunLoop(10);
+ EXPECT_EQ(connectionCount, 0u);
+ }
+
+ {
+ auto webView = adoptNS([WKWebView new]);
+ [webView loadHTMLString:html baseURL:nil];
+ [webView _test_waitForDidFinishNavigation];
+ while (connectionCount != 1)
+ Util::spinRunLoop();
+ }
}
+
+}
Added: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeChangingPlugIn.mm (0 => 280014)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeChangingPlugIn.mm (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/SchemeChangingPlugIn.mm 2021-07-17 01:00:19 UTC (rev 280014)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2021 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.
+ */
+
+#import "config.h"
+
+#import <WebKit/WKWebProcessPlugIn.h>
+#import <WebKit/WKWebProcessPlugInBrowserContextController.h>
+#import <WebKit/WKWebProcessPlugInLoadDelegate.h>
+
+@interface SchemeChangingPlugIn : NSObject <WKWebProcessPlugIn, WKWebProcessPlugInLoadDelegate>
+@end
+
+@implementation SchemeChangingPlugIn
+
+- (void)webProcessPlugIn:(WKWebProcessPlugInController *)plugInController didCreateBrowserContextController:(WKWebProcessPlugInBrowserContextController *)browserContextController
+{
+ [browserContextController setLoadDelegate:self];
+}
+
+- (NSURLRequest *)webProcessPlugInBrowserContextController:(WKWebProcessPlugInBrowserContextController *)controller frame:(WKWebProcessPlugInFrame *)frame willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)redirectResponse
+{
+ NSMutableURLRequest *result = [[request mutableCopy] autorelease];
+ NSURLComponents *components = [NSURLComponents componentsWithURL:request.URL resolvingAgainstBaseURL:NO];
+ components.scheme = @"test+rewritten+scheme";
+ result.URL = ""
+ return result;
+}
+
+@end
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm (280013 => 280014)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm 2021-07-17 00:53:05 UTC (rev 280013)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKURLSchemeHandler-1.mm 2021-07-17 01:00:19 UTC (rev 280014)
@@ -32,6 +32,7 @@
#import "TestUIDelegate.h"
#import "TestURLSchemeHandler.h"
#import "TestWKWebView.h"
+#import "WKWebViewConfigurationExtras.h"
#import <WebKit/WKErrorPrivate.h>
#import <WebKit/WKFrameInfoPrivate.h>
#import <WebKit/WKProcessPoolPrivate.h>
@@ -1619,3 +1620,19 @@
EXPECT_WK_STREQ([webView _test_waitForAlert], "playing");
EXPECT_TRUE(foundRangeRequest);
}
+
+TEST(URLSchemeHandler, HandleURLRewrittenByPlugIn)
+{
+ WKWebViewConfiguration *configuration = [WKWebViewConfiguration _test_configurationWithTestPlugInClassName:@"SchemeChangingPlugIn"];
+ configuration._allowedNetworkHosts = [NSSet set];
+ auto handler = adoptNS([TestURLSchemeHandler new]);
+ __block bool done = false;
+ [handler setStartURLSchemeTaskHandler:^(WKWebView *, id<WKURLSchemeTask> task) {
+ EXPECT_WK_STREQ(task.request.URL.absoluteString, "test+rewritten+scheme://webkit.org/testpath");
+ done = true;
+ }];
+ [configuration setURLSchemeHandler:handler.get() forURLScheme:@"test+rewritten+scheme"];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration]);
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://webkit.org/testpath"]]];
+ TestWebKitAPI::Util::run(&done);
+}