Skip to content

Commit cc3e02d

Browse files
pgorszkowski-igaliaspenap
authored andcommitted
Add web extensions API to allowlist access to a security origin
Allow EmptyOriginAccessPatterns singleton to be used on the WebProcess too. The WebProcess should use the OriginAccessPatternsForWebProcess singleton to handle its access patterns, and the EmptyOriginAccessPatterns is meant to be used just by the rest of the processes. But when implementing the whitelist API, we added a check where we call SecurityOrigin::isSameOriginDomain() to find whether a domain access is whitelisted where we don't need to check the WebProcesss access patterns but just the added allowed mappings. For that case, using OriginAccessPatternsForWebProcess is computational waste, as those checks have already been done, so we use the EmptyOriginAccessPatterns instead.
1 parent 8f2ed5c commit cc3e02d

10 files changed

Lines changed: 61 additions & 2 deletions

File tree

Source/WebCore/page/OriginAccessPatterns.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ bool OriginAccessPatternsForWebProcess::anyPatternMatches(const URL& url) const
7272

7373
const EmptyOriginAccessPatterns& EmptyOriginAccessPatterns::singleton()
7474
{
75-
ASSERT(!isInWebProcess());
7675
static NeverDestroyed<EmptyOriginAccessPatterns> instance;
7776
return instance.get();
7877
}

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 "SecurityPolicy.h"
3738
#include <pal/text/TextEncoding.h>
@@ -291,6 +292,8 @@ bool SecurityOrigin::isSameOriginDomain(const SecurityOrigin& other) const
291292
if (canAccess && isLocal())
292293
canAccess = hasLocalUnseparatedPath(other);
293294

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

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#include <WebCore/DeprecatedGlobalSettings.h>
8282
#include <WebCore/DocumentStorageAccess.h>
8383
#include <WebCore/HTTPCookieAcceptPolicy.h>
84+
#include <WebCore/LegacySchemeRegistry.h>
8485
#include <WebCore/LogInitialization.h>
8586
#include <WebCore/LoginStatus.h>
8687
#include <WebCore/NetworkStorageSession.h>
@@ -780,6 +781,11 @@ void NetworkConnectionToWebProcess::registerURLSchemesAsCORSEnabled(Vector<Strin
780781
registry->registerURLSchemeAsCORSEnabled(WTFMove(scheme));
781782
}
782783

784+
void NetworkConnectionToWebProcess::registerURLSchemeAsHandledBySchemeHandler(const String& scheme)
785+
{
786+
WebCore::LegacySchemeRegistry::registerURLSchemeAsHandledBySchemeHandler(scheme);
787+
}
788+
783789
static bool shouldTreatAsSameSite(const URL& firstParty, const URL& url)
784790
{
785791
#if PLATFORM(COCOA) || USE(SOUP)

Source/WebKit/NetworkProcess/NetworkConnectionToWebProcess.h

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

310310
void registerURLSchemesAsCORSEnabled(Vector<String>&& schemes);
311311

312+
void registerURLSchemeAsHandledBySchemeHandler(const String& scheme);
313+
312314
void cookiesForDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, WebCore::IncludeSecureCookies, WebPageProxyIdentifier, CompletionHandler<void(String cookieString, bool secureCookiesAccessed)>&&);
313315
void setCookiesFromDOM(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, WebCore::FrameIdentifier, WebCore::PageIdentifier, const String& cookieString, WebCore::RequiresScriptTelemetry, WebPageProxyIdentifier);
314316
void cookieRequestHeaderFieldValue(const URL& firstParty, const WebCore::SameSiteInfo&, const URL&, std::optional<WebCore::FrameIdentifier>, std::optional<WebCore::PageIdentifier>, WebCore::IncludeSecureCookies, std::optional<WebPageProxyIdentifier>, 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
@@ -116,6 +116,7 @@ messages -> NetworkConnectionToWebProcess WantsDispatchMessage {
116116
PostMessageToRemote(struct WebCore::MessageWithMessagePorts message, struct WebCore::MessagePortIdentifier remote)
117117
DidDeliverMessagePortMessages(WebKit::MessageBatchIdentifier messageBatchIdentifier)
118118
RegisterURLSchemesAsCORSEnabled(Vector<String> schemes);
119+
RegisterURLSchemeAsHandledBySchemeHandler(String scheme)
119120
SetCORSDisablingPatterns(WebCore::PageIdentifier pageIdentifier, Vector<String> patterns)
120121
#if PLATFORM(MAC)
121122
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
@@ -801,6 +801,7 @@ GI_INTROSPECT(${WPE_WEB_PROCESS_EXTENSION_API_NAME} ${WPE_API_VERSION} wpe/${WPE
801801
${DERIVED_SOURCES_WPE_API_DIR}/WebKitContextMenuActions.h
802802
${DERIVED_SOURCES_WPE_API_DIR}/WebKitContextMenuItem.h
803803
${DERIVED_SOURCES_WPE_API_DIR}/WebKitHitTestResult.h
804+
${DERIVED_SOURCES_WPE_API_DIR}/WebKitSecurityOrigin.h
804805
${DERIVED_SOURCES_WPE_API_DIR}/WebKitUserMessage.h
805806
${DERIVED_SOURCES_WPE_API_DIR}/WebKitURIRequest.h
806807
${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
@@ -8528,6 +8528,7 @@ void WebPage::registerURLSchemeHandler(WebURLSchemeHandlerIdentifier handlerIden
85288528
WebCore::LegacySchemeRegistry::registerURLSchemeAsCORSEnabled(scheme);
85298529
auto schemeResult = m_schemeToURLSchemeHandlerProxyMap.add(scheme, WebURLSchemeHandlerProxy::create(*this, handlerIdentifier));
85308530
m_identifierToURLSchemeHandlerProxyMap.add(handlerIdentifier, Ref { *schemeResult.iterator->value }.get());
8531+
WebProcess::singleton().ensureNetworkProcessConnection().connection().send(Messages::NetworkConnectionToWebProcess::RegisterURLSchemeAsHandledBySchemeHandler { scheme }, 0);
85318532
}
85328533

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

0 commit comments

Comments
 (0)