mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Permit storage keys to use non-opaque origins for file:// URLs
Features like localStorage, sessionStorage, and CacheStorage all work on file:// URLs in other browsers. The spec is a bit uncertain as to when such URLs should be treated as non-opaque, and leave it "as an exercise to the reader". Note that we perform this check in obtain-a-storage-key rather than in the non-storage method, as the latter is also used for e.g. blob:// URL storage.
This commit is contained in:
committed by
Shannon Booth
parent
ef4ff5d490
commit
523e32bbbb
Notes:
github-actions[bot]
2026-04-02 08:22:19 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/523e32bbbb7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8732 Reviewed-by: https://github.com/shannonbooth ✅
@@ -16,6 +16,10 @@ Optional<StorageKey> obtain_a_storage_key(HTML::Environment const& environment)
|
||||
// 1. Let key be the result of running obtain a storage key for non-storage purposes with environment.
|
||||
auto key = obtain_a_storage_key_for_non_storage_purposes(environment);
|
||||
|
||||
// AD-HOC: file:// URLs are opaque, but other browsers support storage on file:// URLs.
|
||||
if (key.origin.is_opaque_file_origin())
|
||||
key.origin = URL::Origin { "file"_string, String {}, {} };
|
||||
|
||||
// 2. If key’s origin is an opaque origin, then return failure.
|
||||
if (key.origin.is_opaque())
|
||||
return {};
|
||||
@@ -36,11 +40,14 @@ StorageKey obtain_a_storage_key_for_non_storage_purposes(URL::Origin const& orig
|
||||
StorageKey obtain_a_storage_key_for_non_storage_purposes(HTML::Environment const& environment)
|
||||
{
|
||||
// 1. Let origin be environment’s origin if environment is an environment settings object; otherwise environment’s creation URL’s origin.
|
||||
if (is<HTML::EnvironmentSettingsObject>(environment)) {
|
||||
auto const& settings = static_cast<HTML::EnvironmentSettingsObject const&>(environment);
|
||||
return { settings.origin() };
|
||||
}
|
||||
return { environment.creation_url.origin() };
|
||||
auto origin = [&]() {
|
||||
if (auto const* settings = as_if<HTML::EnvironmentSettingsObject>(environment))
|
||||
return settings->origin();
|
||||
return environment.creation_url.origin();
|
||||
}();
|
||||
|
||||
// 2. Return a tuple consisting of origin.
|
||||
return { move(origin) };
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user