From 231279cb0d17df77b5a623d5a0a716d5c4217f45 Mon Sep 17 00:00:00 2001 From: Filipe Norte Date: Wed, 10 Jan 2024 15:22:20 +0000 Subject: [PATCH] Fix Security Origin handling in network process Currently, when a custom uri scheme handler is registered, its existence is not passed to the network process. Consequently, when creating a SecurityOrigin object for an URI that uses a custom scheme handler, the instance may be created as unique due shouldTreatAsUniqueOrigin() not detecting the associated scheme as registered (in LegacySchemeRegistry). This will cause calls to SecurityPolicy::isAccessAllowed() to not return the correct authorization in case a custom URI is whitelisted using webkit_web_extension_add_origin_access_whitelist_entry() API, which leads to the inclusion of the "Origin" header with the custom URI in network requests when it should not be included in such case. --- .../WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp | 6 ++++++ .../WebKit/NetworkProcess/NetworkConnectionToWebProcess.h | 2 ++ .../NetworkConnectionToWebProcess.messages.in | 1 + Source/WebKit/WebProcess/WebPage/WebPage.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp index 24e9d0eecb573..105463225d611 100644 --- a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp +++ b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp @@ -75,6 +75,7 @@ #include "WebsiteDataStoreParameters.h" #include #include +#include #include #include #include @@ -1441,6 +1442,11 @@ void NetworkConnectionToWebProcess::installMockContentFilter(WebCore::MockConten } #endif +void NetworkConnectionToWebProcess::registerURLSchemeAsHandledBySchemeHandler(const String& scheme) +{ + WebCore::LegacySchemeRegistry::registerURLSchemeAsHandledBySchemeHandler(scheme); +} + } // namespace WebKit #undef CONNECTION_RELEASE_LOG diff --git a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h index 35deb0171bee0..0828bb7f1fe1f 100644 --- a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h +++ b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h @@ -239,6 +239,8 @@ class NetworkConnectionToWebProcess void registerURLSchemesAsCORSEnabled(Vector&& schemes); + void registerURLSchemeAsHandledBySchemeHandler(const String& scheme); + void cookiesForDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, WebCore::IncludeSecureCookies, WebCore::ShouldAskITP, WebCore::ShouldRelaxThirdPartyCookieBlocking, CompletionHandler&&); void setCookiesFromDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, WebCore::ShouldAskITP, const String&, WebCore::ShouldRelaxThirdPartyCookieBlocking); void cookieRequestHeaderFieldValue(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, std::optional, std::optional, WebCore::IncludeSecureCookies, WebCore::ShouldAskITP, WebCore::ShouldRelaxThirdPartyCookieBlocking, CompletionHandler&&); diff --git a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in index 2ab3c78324601..4be02327c964f 100644 --- a/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in +++ b/Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in @@ -117,4 +117,5 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver { #if ENABLE(CONTENT_FILTERING_IN_NETWORKING_PROCESS) InstallMockContentFilter(WebCore::MockContentFilterSettings settings) #endif + RegisterURLSchemeAsHandledBySchemeHandler(String scheme) } diff --git a/Source/WebKit/WebProcess/WebPage/WebPage.cpp b/Source/WebKit/WebProcess/WebPage/WebPage.cpp index b8ec4d02e6713..540cd69c45a7a 100644 --- a/Source/WebKit/WebProcess/WebPage/WebPage.cpp +++ b/Source/WebKit/WebProcess/WebPage/WebPage.cpp @@ -7285,6 +7285,8 @@ void WebPage::registerURLSchemeHandler(WebURLSchemeHandlerIdentifier handlerIden WebCore::LegacySchemeRegistry::registerURLSchemeAsCORSEnabled(scheme); auto schemeResult = m_schemeToURLSchemeHandlerProxyMap.add(scheme, WebURLSchemeHandlerProxy::create(*this, handlerIdentifier)); m_identifierToURLSchemeHandlerProxyMap.add(handlerIdentifier, schemeResult.iterator->value.get()); + + WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RegisterURLSchemeAsHandledBySchemeHandler { scheme }, 0); } void WebPage::urlSchemeTaskWillPerformRedirection(WebURLSchemeHandlerIdentifier handlerIdentifier, WebCore::ResourceLoaderIdentifier taskIdentifier, ResourceResponse&& response, ResourceRequest&& request, CompletionHandler&& completionHandler)