Skip to content

Commit dc713f8

Browse files
filipe-norte-redmagomez
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 b82f4fd commit dc713f8

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
@@ -5620,6 +5620,33 @@ void webkit_web_view_set_cors_allowlist(WebKitWebView* webView, const gchar* con
56205620
getPage(webView).setCORSDisablingPatterns(WTFMove(allowListVector));
56215621
}
56225622

5623+
5624+
/**
5625+
* webkit_web_view_set_local_universal_access_allowlist:
5626+
* @web_view: a #WebKitWebView
5627+
* @allowlist: (array zero-terminated=1) (element-type utf8) (transfer none) (nullable): an allowlist of URIs, or %NULL
5628+
*
5629+
* Sets the @allowlist for which local universal access is granted.
5630+
*
5631+
* If this function is called multiple times, only the allowlist set by
5632+
* the most recent call will be effective.
5633+
*
5634+
* Since: 2.46
5635+
*/
5636+
void webkit_web_view_set_local_universal_access_allowlist(WebKitWebView* webView, const gchar* const* allowList)
5637+
{
5638+
g_return_if_fail(WEBKIT_IS_WEB_VIEW(webView));
5639+
5640+
Vector<String> allowListVector;
5641+
if (allowList) {
5642+
for (auto str = allowList; *str; ++str)
5643+
allowListVector.append(String::fromUTF8(*str));
5644+
}
5645+
5646+
getPage(webView).setLocalUniversalAccessAllowList(WTFMove(allowListVector));
5647+
}
5648+
5649+
56235650
static void webkitWebViewConfigureMediaCapture(WebKitWebView* webView, WebCore::MediaProducerMediaCaptureKind captureKind, WebKitMediaCaptureState captureState)
56245651
{
56255652
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
@@ -11913,6 +11913,7 @@ WebPageCreationParameters WebPageProxy::creationParameters(WebProcessProxy& proc
1191311913

1191411914
parameters.overriddenMediaType = m_overriddenMediaType;
1191511915
parameters.corsDisablingPatterns = corsDisablingPatterns();
11916+
parameters.localUniversalAccessAllowList = localUniversalAccessAllowList();
1191611917
parameters.maskedURLSchemes = m_configuration->maskedURLSchemes();
1191711918
parameters.allowedNetworkHosts = m_configuration->allowedNetworkHosts();
1191811919
parameters.loadsSubresources = m_configuration->loadsSubresources();
@@ -15209,6 +15210,12 @@ void WebPageProxy::setCORSDisablingPatterns(Vector<String>&& patterns)
1520915210
send(Messages::WebPage::UpdateCORSDisablingPatterns(m_corsDisablingPatterns));
1521015211
}
1521115212

15213+
void WebPageProxy::setLocalUniversalAccessAllowList(Vector<String>&& allowList)
15214+
{
15215+
m_localUniversalAccessAllowList = WTFMove(allowList);
15216+
send(Messages::WebPage::SetLocalUniversalAccessAllowList(m_localUniversalAccessAllowList));
15217+
}
15218+
1521215219
void WebPageProxy::setOverriddenMediaType(const String& mediaType)
1521315220
{
1521415221
m_overriddenMediaType = mediaType;

Source/WebKit/UIProcess/WebPageProxy.h

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

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

22592262
void setOrientationForMediaCapture(WebCore::IntDegrees);
@@ -3833,6 +3836,7 @@ class WebPageProxy final : public API::ObjectImpl<API::Object::Type::Page>, publ
38333836
String m_overriddenMediaType;
38343837

38353838
Vector<String> m_corsDisablingPatterns;
3839+
Vector<String> m_localUniversalAccessAllowList;
38363840

38373841
struct InjectedBundleMessage {
38383842
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

@@ -9125,6 +9127,11 @@ void WebPage::updateCORSDisablingPatterns(Vector<String>&& patterns)
91259127
page->setCORSDisablingPatterns(parseAndAllowAccessToCORSDisablingPatterns(m_corsDisablingPatterns));
91269128
}
91279129

9130+
void WebPage::setLocalUniversalAccessAllowList(Vector<String>&& allowList)
9131+
{
9132+
m_localUniversalAccessAllowList = WTFMove(allowList);
9133+
}
9134+
91289135
void WebPage::synchronizeCORSDisablingPatternsWithNetworkProcess()
91299136
{
91309137
// 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
@@ -1740,6 +1740,7 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
17401740
void setOverriddenMediaType(const String&);
17411741

17421742
void updateCORSDisablingPatterns(Vector<String>&&);
1743+
void setLocalUniversalAccessAllowList(Vector<String>&&);
17431744

17441745
#if ENABLE(IPC_TESTING_API)
17451746
bool ipcTestingAPIEnabled() const { return m_ipcTestingAPIEnabled; }
@@ -2005,6 +2006,8 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
20052006

20062007
std::unique_ptr<FrameInfoData> takeMainFrameNavigationInitiator();
20072008

2009+
const Vector<String>& localUniversalAccessAllowList() const { return m_localUniversalAccessAllowList; };
2010+
20082011
private:
20092012
WebPage(WebCore::PageIdentifier, WebPageCreationParameters&&);
20102013

@@ -3039,6 +3042,7 @@ class WebPage final : public API::ObjectImpl<API::Object::Type::BundlePage>, pub
30393042
bool m_textManipulationIncludesSubframes { false };
30403043

30413044
Vector<String> m_corsDisablingPatterns;
3045+
Vector<String> m_localUniversalAccessAllowList;
30423046

30433047
std::unique_ptr<WebCore::CachedPage> m_cachedPage;
30443048

0 commit comments

Comments
 (0)