Skip to content

Commit 695c76a

Browse files
Add web extensions API to allowlist access to a security origin
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.
1 parent 2523172 commit 695c76a

9 files changed

Lines changed: 61 additions & 1 deletion

File tree

Source/WebCore/page/SecurityOrigin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "BlobURL.h"
3333
#include "LegacySchemeRegistry.h"
3434
#include "OriginAccessEntry.h"
35+
#include "OriginAccessPatterns.h"
3536
#include "PublicSuffixStore.h"
3637
#include "RuntimeApplicationChecks.h"
3738
#include "SecurityPolicy.h"
@@ -290,6 +291,8 @@ bool SecurityOrigin::isSameOriginDomain(const SecurityOrigin& other) const
290291
if (canAccess && isLocal())
291292
canAccess = passesFileCheck(other);
292293

294+
canAccess |= SecurityPolicy::isAccessAllowed(*this, other, other.toURL(), EmptyOriginAccessPatterns::singleton());
295+
293296
return canAccess;
294297
}
295298

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include <WebCore/DeprecatedGlobalSettings.h>
8383
#include <WebCore/DocumentStorageAccess.h>
8484
#include <WebCore/HTTPCookieAcceptPolicy.h>
85+
#include <WebCore/LegacySchemeRegistry.h>
8586
#include <WebCore/LogInitialization.h>
8687
#include <WebCore/NetworkStorageSession.h>
8788
#include <WebCore/ResourceError.h>
@@ -771,6 +772,11 @@ void NetworkConnectionToWebProcess::registerURLSchemesAsCORSEnabled(Vector<Strin
771772
m_schemeRegistry->registerURLSchemeAsCORSEnabled(WTFMove(scheme));
772773
}
773774

775+
void NetworkConnectionToWebProcess::registerURLSchemeAsHandledBySchemeHandler(const String& scheme)
776+
{
777+
WebCore::LegacySchemeRegistry::registerURLSchemeAsHandledBySchemeHandler(scheme);
778+
}
779+
774780
void NetworkConnectionToWebProcess::cookiesForDOM(const URL& firstParty, const SameSiteInfo& sameSiteInfo, const URL& url, FrameIdentifier frameID, PageIdentifier pageID, IncludeSecureCookies includeSecureCookies, ApplyTrackingPrevention applyTrackingPrevention, ShouldRelaxThirdPartyCookieBlocking shouldRelaxThirdPartyCookieBlocking, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&& completionHandler)
775781
{
776782
MESSAGE_CHECK_COMPLETION(m_networkProcess->allowsFirstPartyForCookies(m_webProcessIdentifier, firstParty), completionHandler({ }, false));

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ class NetworkConnectionToWebProcess
271271

272272
void registerURLSchemesAsCORSEnabled(Vector<String>&& schemes);
273273

274+
void registerURLSchemeAsHandledBySchemeHandler(const String& scheme);
275+
274276
void cookiesForDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, WebCore::IncludeSecureCookies, WebCore::ApplyTrackingPrevention, WebCore::ShouldRelaxThirdPartyCookieBlocking, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&&);
275277
void setCookiesFromDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, WebCore::ApplyTrackingPrevention, const String& cookieString, WebCore::ShouldRelaxThirdPartyCookieBlocking);
276278
void cookieRequestHeaderFieldValue(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, std::optional<WebCore::FrameIdentifier>, std::optional<WebCore::PageIdentifier>, WebCore::IncludeSecureCookies, WebCore::ApplyTrackingPrevention, WebCore::ShouldRelaxThirdPartyCookieBlocking, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&&);

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.messages.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ messages -> NetworkConnectionToWebProcess LegacyReceiver {
109109
PostMessageToRemote(struct WebCore::MessageWithMessagePorts message, struct WebCore::MessagePortIdentifier remote)
110110
DidDeliverMessagePortMessages(uint64_t messageBatchIdentifier)
111111
RegisterURLSchemesAsCORSEnabled(Vector<String> schemes);
112+
RegisterURLSchemeAsHandledBySchemeHandler(String scheme)
112113
SetCORSDisablingPatterns(WebCore::PageIdentifier pageIdentifier, Vector<String> patterns)
113114
#if PLATFORM(MAC)
114115
GetProcessDisplayName(struct WebKit::CoreIPCAuditToken auditToken) -> (String displayName)

Source/WebKit/PlatformWPE.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ GI_INTROSPECT(${WPE_WEB_PROCESS_EXTENSION_API_NAME} ${WPE_API_VERSION} wpe/${WPE
730730
${DERIVED_SOURCES_WPE_API_DIR}/WebKitContextMenuActions.h
731731
${DERIVED_SOURCES_WPE_API_DIR}/WebKitContextMenuItem.h
732732
${DERIVED_SOURCES_WPE_API_DIR}/WebKitHitTestResult.h
733+
${DERIVED_SOURCES_WPE_API_DIR}/WebKitSecurityOrigin.h
733734
${DERIVED_SOURCES_WPE_API_DIR}/WebKitUserMessage.h
734735
${DERIVED_SOURCES_WPE_API_DIR}/WebKitURIRequest.h
735736
${DERIVED_SOURCES_WPE_API_DIR}/WebKitURIResponse.h

Source/WebKit/UIProcess/API/glib/WebKitSecurityOrigin.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* Boston, MA 02110-1301, USA.
1818
*/
1919

20-
@API_SINGLE_HEADER_CHECK@
20+
@SHARED_API_SINGLE_HEADER_CHECK@
2121

2222
#ifndef WebKitSecurityOrigin_h
2323
#define WebKitSecurityOrigin_h

Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebExtension.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "APIDictionary.h"
2424
#include "APIInjectedBundleBundleClient.h"
2525
#include "APIString.h"
26+
#include "WebKitSecurityOriginPrivate.h"
2627
#include "WebKitUserMessagePrivate.h"
2728
#include "WebKitWebPagePrivate.h"
2829
#include "WebKitWebProcessExtensionPrivate.h"
@@ -122,6 +123,7 @@ enum {
122123
typedef HashMap<WebPage*, GRefPtr<WebKitWebPage> > WebPageMap;
123124

124125
struct _WebKitWebExtensionPrivate {
126+
RefPtr<InjectedBundle> bundle;
125127
WebPageMap pages;
126128
#if ENABLE(DEVELOPER_MODE)
127129
bool garbageCollectOnPageDestroy;
@@ -204,6 +206,7 @@ class WebExtensionInjectedBundleClient final : public API::InjectedBundle::Clien
204206
WebKitWebExtension* webkitWebProcessExtensionCreate(InjectedBundle* bundle)
205207
{
206208
WebKitWebExtension* extension = WEBKIT_WEB_EXTENSION(g_object_new(WEBKIT_TYPE_WEB_EXTENSION, NULL));
209+
extension->priv->bundle = bundle;
207210
bundle->setClient(makeUnique<WebExtensionInjectedBundleClient>(extension));
208211
return extension;
209212
}
@@ -246,6 +249,31 @@ WebKitWebPage* webkit_web_extension_get_page(WebKitWebExtension* extension, guin
246249
return 0;
247250
}
248251

252+
void webkit_web_extension_add_origin_access_whitelist_entry(WebKitWebExtension* extension, WebKitSecurityOrigin* origin, const char* protocol, const char* host, gboolean allowSubdomains)
253+
{
254+
g_return_if_fail(WEBKIT_IS_WEB_EXTENSION(extension));
255+
g_return_if_fail(origin);
256+
g_return_if_fail(protocol);
257+
258+
extension->priv->bundle->addOriginAccessAllowListEntry(webkitSecurityOriginGetSecurityOriginData(origin).toString(), String::fromUTF8(protocol), String::fromUTF8(host), host ? allowSubdomains : true);
259+
}
260+
261+
void webkit_web_extension_remove_origin_access_whitelist_entry(WebKitWebExtension* extension, WebKitSecurityOrigin* origin, const char* protocol, const char* host, gboolean allowSubdomains)
262+
{
263+
g_return_if_fail(WEBKIT_IS_WEB_EXTENSION(extension));
264+
g_return_if_fail(origin);
265+
g_return_if_fail(protocol);
266+
267+
extension->priv->bundle->removeOriginAccessAllowListEntry(webkitSecurityOriginGetSecurityOriginData(origin).toString(), String::fromUTF8(protocol), String::fromUTF8(host), host ? allowSubdomains : true);
268+
}
269+
270+
void webkit_web_extension_reset_origin_access_whitelists(WebKitWebExtension* extension)
271+
{
272+
g_return_if_fail(WEBKIT_IS_WEB_EXTENSION(extension));
273+
274+
extension->priv->bundle->resetOriginAccessAllowLists();
275+
}
276+
249277
/**
250278
* webkit_web_extension_send_message_to_context:
251279
* @extension: a #WebKitWebExtension

Source/WebKit/WebProcess/InjectedBundle/API/glib/WebKitWebExtension.h.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <glib-object.h>
2626
#include <@API_INCLUDE_PREFIX@/WebKitDefines.h>
27+
#include <@API_INCLUDE_PREFIX@/WebKitSecurityOrigin.h>
2728
#include <@API_INCLUDE_PREFIX@/WebKitUserMessage.h>
2829
#include <@API_INCLUDE_PREFIX@/WebKitWebPage.h>
2930

@@ -74,6 +75,23 @@ WEBKIT_API WebKitWebPage *
7475
webkit_web_extension_get_page (WebKitWebExtension *extension,
7576
guint64 page_id);
7677

78+
WEBKIT_API void
79+
webkit_web_extension_add_origin_access_whitelist_entry (WebKitWebExtension *extension,
80+
WebKitSecurityOrigin *origin,
81+
const gchar *protocol,
82+
const gchar *host,
83+
gboolean allow_subdomains);
84+
85+
WEBKIT_API void
86+
webkit_web_extension_remove_origin_access_whitelist_entry (WebKitWebExtension *extension,
87+
WebKitSecurityOrigin *origin,
88+
const gchar *protocol,
89+
const gchar *host,
90+
gboolean allow_subdomains);
91+
92+
WEBKIT_API void
93+
webkit_web_extension_reset_origin_access_whitelists (WebKitWebExtension *extension);
94+
7795
WEBKIT_API void
7896
webkit_web_extension_send_message_to_context (WebKitWebExtension *extension,
7997
WebKitUserMessage *message,

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8115,6 +8115,7 @@ void WebPage::registerURLSchemeHandler(WebURLSchemeHandlerIdentifier handlerIden
81158115
WebCore::LegacySchemeRegistry::registerURLSchemeAsCORSEnabled(scheme);
81168116
auto schemeResult = m_schemeToURLSchemeHandlerProxyMap.add(scheme, WebURLSchemeHandlerProxy::create(*this, handlerIdentifier));
81178117
m_identifierToURLSchemeHandlerProxyMap.add(handlerIdentifier, *schemeResult.iterator->value);
8118+
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RegisterURLSchemeAsHandledBySchemeHandler { scheme }, 0);
81188119
}
81198120

81208121
void WebPage::urlSchemeTaskWillPerformRedirection(WebURLSchemeHandlerIdentifier handlerIdentifier, WebCore::ResourceLoaderIdentifier taskIdentifier, ResourceResponse&& response, ResourceRequest&& request, CompletionHandler<void(WebCore::ResourceRequest&&)>&& completionHandler)

0 commit comments

Comments
 (0)