Title: [295157] trunk
- Revision
- 295157
- Author
- [email protected]
- Date
- 2022-06-02 17:20:24 -0700 (Thu, 02 Jun 2022)
Log Message
PreconnectTask should follow HSTS "redirects"
https://bugs.webkit.org/show_bug.cgi?id=241237
rdar://92870039
Reviewed by Chris Dumez.
NetworkLoadClient::willSendRedirectedRequest requires callees to call
NetworkLoad::continueWillSendRequest when finished.
This should be refactored into a direct completion handler call instead of
storing the completion handler on the NetworkLoad, but that is more invasive
and should be done in a separate PR that will be harder to merge to branches.
* Source/WebKit/NetworkProcess/PreconnectTask.cpp:
(WebKit::PreconnectTask::willSendRedirectedRequest):
* Tools/TestWebKitAPI/Tests/WebKitCocoa/HSTS.mm:
(TestWebKitAPI::TEST):
* Tools/TestWebKitAPI/cocoa/HTTPServer.h:
(TestWebKitAPI::Connection::terminate):
* Tools/TestWebKitAPI/cocoa/HTTPServer.mm:
(TestWebKitAPI::Connection::terminate):
Canonical link: https://commits.webkit.org/251244@main
Modified Paths
Diff
Modified: trunk/Source/WebKit/NetworkProcess/PreconnectTask.cpp (295156 => 295157)
--- trunk/Source/WebKit/NetworkProcess/PreconnectTask.cpp 2022-06-03 00:13:40 UTC (rev 295156)
+++ trunk/Source/WebKit/NetworkProcess/PreconnectTask.cpp 2022-06-03 00:20:24 UTC (rev 295157)
@@ -70,7 +70,14 @@
void PreconnectTask::willSendRedirectedRequest(ResourceRequest&&, ResourceRequest&& redirectRequest, ResourceResponse&& redirectResponse)
{
- // HSTS redirection may happen here.
+ // HSTS "redirection" may happen here.
+#if ASSERT_ENABLED
+ auto url = ""
+ ASSERT(url.protocol() == "http"_s);
+ url.setProtocol("https"_s);
+ ASSERT(redirectRequest.url() == url);
+#endif
+ m_networkLoad->continueWillSendRequest(WTFMove(redirectRequest));
}
void PreconnectTask::didReceiveResponse(ResourceResponse&& response, PrivateRelayed, ResponseCompletionHandler&& completionHandler)
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/HSTS.mm (295156 => 295157)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/HSTS.mm 2022-06-03 00:13:40 UTC (rev 295156)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/HSTS.mm 2022-06-03 00:20:24 UTC (rev 295157)
@@ -141,6 +141,50 @@
EXPECT_EQ(httpServer.totalRequests(), 1u);
}
+TEST(HSTS, Preconnect)
+{
+ bool firstConnectionTerminated { false };
+ bool secondConnectionReceived { false };
+ HTTPServer server([&secondConnectionReceived, &firstConnectionTerminated, connectionCount = 0] (Connection connection) mutable {
+ if (!connectionCount++) {
+ connection.receiveHTTPRequest([connection, &firstConnectionTerminated] (Vector<char>) {
+ auto response =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 3\r\n"
+ "Strict-Transport-Security: max-age=31536000\r\n"
+ "\r\n"
+ "hi!"_s;
+ connection.send(response, [connection, &firstConnectionTerminated] () mutable {
+ connection.terminate([&firstConnectionTerminated] {
+ firstConnectionTerminated = true;
+ });
+ });
+ });
+ return;
+ }
+ secondConnectionReceived = true;
+ }, HTTPServer::Protocol::HttpsProxy);
+
+ auto storeConfiguration = adoptNS([[_WKWebsiteDataStoreConfiguration alloc] initNonPersistentConfiguration]);
+ [storeConfiguration setHTTPSProxy:[NSURL URLWithString:[NSString stringWithFormat:@"https://127.0.0.1:%d/", server.port()]]];
+ [storeConfiguration setAllowsHSTSWithUntrustedRootCertificate:YES];
+ auto viewConfiguration = adoptNS([WKWebViewConfiguration new]);
+ [viewConfiguration setWebsiteDataStore:adoptNS([[WKWebsiteDataStore alloc] _initWithConfiguration:storeConfiguration.get()]).get()];
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:viewConfiguration.get()]);
+ auto delegate = adoptNS([TestNavigationDelegate new]);
+ [webView setNavigationDelegate:delegate.get()];
+ delegate.get().didReceiveAuthenticationChallenge = ^(WKWebView *, NSURLAuthenticationChallenge *challenge, void (^completionHandler)(NSURLSessionAuthChallengeDisposition, NSURLCredential *)) {
+ EXPECT_WK_STREQ(challenge.protectionSpace.authenticationMethod, NSURLAuthenticationMethodServerTrust);
+ completionHandler(NSURLSessionAuthChallengeUseCredential, [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]);
+ };
+
+ [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://example.com/"]]];
+ TestWebKitAPI::Util::run(&firstConnectionTerminated);
+
+ [webView _preconnectToServer:[NSURL URLWithString:@"http://example.com/"]];
+ TestWebKitAPI::Util::run(&secondConnectionReceived);
+}
+
#endif // HAVE(CFNETWORK_NSURLSESSION_HSTS_WITH_UNTRUSTED_ROOT)
} // namespace TestWebKitAPI
Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h (295156 => 295157)
--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h 2022-06-03 00:13:40 UTC (rev 295156)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.h 2022-06-03 00:20:24 UTC (rev 295157)
@@ -119,7 +119,7 @@
void receiveHTTPRequest(CompletionHandler<void(Vector<char>&&)>&&, Vector<char>&& buffer = { }) const;
ReceiveOperation awaitableReceiveHTTPRequest() const;
void webSocketHandshake(CompletionHandler<void()>&& = { });
- void terminate();
+ void terminate(CompletionHandler<void()>&& = { });
void cancel();
private:
Modified: trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm (295156 => 295157)
--- trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm 2022-06-03 00:13:40 UTC (rev 295156)
+++ trunk/Tools/TestWebKitAPI/cocoa/HTTPServer.mm 2022-06-03 00:20:24 UTC (rev 295157)
@@ -529,8 +529,13 @@
});
}
-void Connection::terminate()
+void Connection::terminate(CompletionHandler<void()>&& completionHandler)
{
+ nw_connection_set_state_changed_handler(m_connection.get(), makeBlockPtr([completionHandler = WTFMove(completionHandler)] (nw_connection_state_t state, nw_error_t error) mutable {
+ ASSERT_UNUSED(error, !error);
+ if (state == nw_connection_state_cancelled && completionHandler)
+ completionHandler();
+ }).get());
nw_connection_cancel(m_connection.get());
}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes