Skip to content

Commit 6c4af24

Browse files
filipe-norte-redspenap
authored andcommitted
Support whitelisting URLs for local universal access
When launching the browser with a local (file) URL, the page may need to load scripts that reside on a different volume. The commit 448487f introduced a change to use the posix version of FileSystem::getFileDeviceId() instead of the glib one. This affected the return value which is now non-zero, fixing a bug, but changing the behavior of FileSystem::filesHaveSameVolume() compared to older versions and consequently the behavior of SecurityOrigin::canDisplay() when a page loads a script that resides on a different volume. While this can be overcome by enabling the setting to allow universal access from file urls using the API webkit_settings_set_allow_universal_access_from_file_urls(), that will allow a wider access that needed, as the access is only required from a limited number of trusted local files. This new API introduces a way to overcome this issue and allow only the access that is required.
1 parent f71742c commit 6c4af24

File tree

11 files changed

+63
-0
lines changed

11 files changed

+63
-0
lines changed

Source/WebKit/Shared/WebPageCreationParameters.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ struct WebPageCreationParameters {
270270

271271
String overriddenMediaType { };
272272
Vector<String> corsDisablingPatterns { };
273+
Vector<String> localUniversalAccessAllowList { };
273274
HashSet<String> maskedURLSchemes { };
274275
bool loadsSubresources { true };
275276
std::optional<MemoryCompactLookupOnlyRobinHoodHashSet<String>> allowedNetworkHosts { };

Source/WebKit/Shared/WebPageCreationParameters.serialization.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ enum class WebCore::UserInterfaceLayoutDirection : bool;
191191

192192
String overriddenMediaType;
193193
Vector<String> corsDisablingPatterns;
194+
Vector<String> localUniversalAccessAllowList;
194195
HashSet<String> maskedURLSchemes;
195196
bool loadsSubresources;
196197
std::optional<MemoryCompactLookupOnlyRobinHoodHashSet<String>> allowedNetworkHosts;

Source/WebKit/UIProcess/API/APIPageConfiguration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ class PageConfiguration : public ObjectImpl<Object::Type::PageConfiguration> {
574574

575575
HashMap<WTF::String, Ref<WebKit::WebURLSchemeHandler>> urlSchemeHandlers;
576576
Vector<WTF::String> corsDisablingPatterns;
577+
Vector<WTF::String> localUniversalAccessAllowList;
577578
HashSet<WTF::String> maskedURLSchemes;
578579
bool maskedURLSchemesWasSet { false };
579580
bool crossOriginAccessControlCheckEnabled { true };

Source/WebKit/UIProcess/API/glib/WebKitWebView.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5613,6 +5613,33 @@ void webkit_web_view_set_cors_allowlist(WebKitWebView* webView, const gchar* con
56135613
getPage(webView).setCORSDisablingPatterns(WTFMove(allowListVector));
56145614
}
56155615

5616+
5617+
/**
5618+
* webkit_web_view_set_local_universal_access_allowlist:
5619+
* @web_view: a #WebKitWebView
5620+
* @allowlist: (array zero-terminated=1) (element-type utf8) (transfer none) (nullable): an allowlist of URIs, or %NULL
5621+
*
5622+
* Sets the @allowlist for which local universal access is granted.
5623+
*
5624+
* If this function is called multiple times, only the allowlist set by
5625+
* the most recent call will be effective.
5626+
*
5627+
* Since: 2.46
5628+
*/
5629+
void webkit_web_view_set_local_universal_access_allowlist(WebKitWebView* webView, const gchar* const* allowList)
5630+
{
5631+
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
5632+
5633+
Vector<String> allowListVector;
5634+
if (allowList) {
5635+
for (auto str = allowList; *str; ++str)
5636+
allowListVector.append(String::fromUTF8(*str));
5637+
}
5638+
5639+
getPage(webView).setLocalUniversalAccessAllowList(WTFMove(allowListVector));
5640+
}
5641+
5642+
56165643
static void webkitWebViewConfigureMediaCapture(WebKitWebView* webView, WebCore::MediaProducerMediaCaptureKind captureKind, WebKitMediaCaptureState captureState)
56175644
{
56185645
Ref page = getPage(webView);

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,10 @@ WEBKIT_API void
872872
webkit_web_view_set_cors_allowlist (WebKitWebView *web_view,
873873
const gchar * const *allowlist);
874874

875+
WEBKIT_API void
876+
webkit_web_view_set_local_universal_access_allowlist (WebKitWebView *web_view,
877+
const gchar * const *allowlist);
878+
875879
WEBKIT_API WebKitWebsitePolicies *
876880
webkit_web_view_get_website_policies (WebKitWebView *web_view);
877881

Source/WebKit/UIProcess/WebPageProxy.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11883,6 +11883,7 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
1188311883

1188411884
parameters.overriddenMediaType = m_overriddenMediaType;
1188511885
parameters.corsDisablingPatterns = corsDisablingPatterns();
11886+
parameters.localUniversalAccessAllowList = localUniversalAccessAllowList();
1188611887
parameters.maskedURLSchemes = m_configuration->maskedURLSchemes();
1188711888
parameters.allowedNetworkHosts = m_configuration->allowedNetworkHosts();
1188811889
parameters.loadsSubresources = m_configuration->loadsSubresources();
@@ -15179,6 +15180,12 @@ void WebPageProxy::setCORSDisablingPatterns(Vector<String>&& patterns)
1517915180
send(Messages::WebPage::UpdateCORSDisablingPatterns(m_corsDisablingPatterns));
1518015181
}
1518115182

15183+
void WebPageProxy::setLocalUniversalAccessAllowList(Vector<String>&& allowList)
15184+
{
15185+
m_localUniversalAccessAllowList = WTFMove(allowList);
15186+
send(Messages::WebPage::SetLocalUniversalAccessAllowList(m_localUniversalAccessAllowList));
15187+
}
15188+
1518215189
void WebPageProxy::setOverriddenMediaType(const String& mediaType)
1518315190
{
1518415191
m_overriddenMediaType = mediaType;

Source/WebKit/UIProcess/WebPageProxy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,9 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
22532253
void setCORSDisablingPatterns(Vector<String>&&);
22542254
const Vector<String>& corsDisablingPatterns() const { return m_corsDisablingPatterns; }
22552255

2256+
void setLocalUniversalAccessAllowList(Vector<String>&&);
2257+
const Vector<String>& localUniversalAccessAllowList() const { return m_localUniversalAccessAllowList; }
2258+
22562259
void getProcessDisplayName(CompletionHandler<void(String&&)>&&);
22572260

22582261
void setOrientationForMediaCapture(WebCore::IntDegrees);
@@ -3829,6 +3832,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
38293832
String m_overriddenMediaType;
38303833

38313834
Vector<String> m_corsDisablingPatterns;
3835+
Vector<String> m_localUniversalAccessAllowList;
38323836

38333837
struct InjectedBundleMessage {
38343838
String messageName;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ class PageLoaderClient final : public API::InjectedBundle::PageLoaderClient {
283283
{
284284
}
285285

286+
bool shouldForceUniversalAccessFromLocalURL(WebKit::WebPage& webPage, const WTF::String& url) override
287+
{
288+
return webPage.localUniversalAccessAllowList().contains(url);
289+
}
290+
286291
WebKitWebPage* m_webPage;
287292
};
288293

Source/WebKit/WebProcess/WebPage/WebPage.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,8 @@ WebPage::WebPage(PageIdentifier pageID, WebPageCreationParameters&& parameters)
853853
pageConfiguration.httpsUpgradeEnabled = parameters.httpsUpgradeEnabled;
854854
pageConfiguration.portsForUpgradingInsecureSchemeForTesting = parameters.portsForUpgradingInsecureSchemeForTesting;
855855

856+
m_localUniversalAccessAllowList = WTFMove(parameters.localUniversalAccessAllowList);
857+
856858
if (!parameters.crossOriginAccessControlCheckEnabled)
857859
CrossOriginAccessControlCheckDisabler::singleton().setCrossOriginAccessControlCheckEnabled(false);
858860

@@ -9140,6 +9142,11 @@ void WebPage::updateCORSDisablingPatterns(Vector<String>&& patterns)
91409142
page->setCORSDisablingPatterns(parseAndAllowAccessToCORSDisablingPatterns(m_corsDisablingPatterns));
91419143
}
91429144

9145+
void WebPage::setLocalUniversalAccessAllowList(Vector<String>&& allowList)
9146+
{
9147+
m_localUniversalAccessAllowList = WTFMove(allowList);
9148+
}
9149+
91439150
void WebPage::synchronizeCORSDisablingPatternsWithNetworkProcess()
91449151
{
91459152
// FIXME: We should probably have this mechanism done between UIProcess and NetworkProcess directly.

Source/WebKit/WebProcess/WebPage/WebPage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,7 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
17441744
void setOverriddenMediaType(const String&);
17451745

17461746
void updateCORSDisablingPatterns(Vector<String>&&);
1747+
void setLocalUniversalAccessAllowList(Vector<String>&&);
17471748

17481749
#if ENABLE(IPC_TESTING_API)
17491750
bool ipcTestingAPIEnabled() const { return m_ipcTestingAPIEnabled; }
@@ -2009,6 +2010,8 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
20092010

20102011
std::unique_ptr<FrameInfoData> takeMainFrameNavigationInitiator();
20112012

2013+
const Vector<String>& localUniversalAccessAllowList() const { return m_localUniversalAccessAllowList; };
2014+
20122015
private:
20132016
WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
20142017

@@ -3044,6 +3047,7 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
30443047
bool m_textManipulationIncludesSubframes { false };
30453048

30463049
Vector<String> m_corsDisablingPatterns;
3050+
Vector<String> m_localUniversalAccessAllowList;
30473051

30483052
std::unique_ptr<WebCore::CachedPage> m_cachedPage;
30493053

0 commit comments

Comments
 (0)