mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
LibURL+Elsewhere: Consider file:// origins opaque by default
This aligns our behaviour closer to other browsers, which _mostly_ consider file scheme URLs as opaque. For test purposes, allow overriding this behaviour with a commandline flag.
This commit is contained in:
committed by
Jelle Raaijmakers
parent
d6d80e5d52
commit
1be69479a6
Notes:
github-actions[bot]
2026-02-21 22:02:13 +00:00
Author: https://github.com/shannonbooth Commit: https://github.com/LadybirdBrowser/ladybird/commit/1be69479a62 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7309 Reviewed-by: https://github.com/gmta ✅
@@ -19,6 +19,8 @@
|
||||
|
||||
namespace URL {
|
||||
|
||||
static bool s_file_scheme_urls_have_tuple_origins = false;
|
||||
|
||||
Optional<URL> URL::complete_url(StringView relative_url) const
|
||||
{
|
||||
return Parser::basic_parse(relative_url, *this);
|
||||
@@ -316,6 +318,17 @@ ByteString URL::serialize_for_display() const
|
||||
return builder.to_byte_string();
|
||||
}
|
||||
|
||||
void set_file_scheme_urls_have_tuple_origins()
|
||||
{
|
||||
VERIFY(!s_file_scheme_urls_have_tuple_origins);
|
||||
s_file_scheme_urls_have_tuple_origins = true;
|
||||
}
|
||||
|
||||
bool file_scheme_urls_have_tuple_origins()
|
||||
{
|
||||
return s_file_scheme_urls_have_tuple_origins;
|
||||
}
|
||||
|
||||
// https://url.spec.whatwg.org/#concept-url-origin
|
||||
Origin URL::origin() const
|
||||
{
|
||||
@@ -355,8 +368,21 @@ Origin URL::origin() const
|
||||
// AD-HOC: Our resource:// is basically an alias to file://
|
||||
if (scheme() == "file"sv || scheme() == "resource"sv) {
|
||||
// Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
|
||||
// Note: We must return an origin with the `file://' protocol for `file://' iframes to work from `file://' pages.
|
||||
return Origin(scheme(), String {}, {});
|
||||
|
||||
// Our implementation-defined behavior is to return an opaque origin for file:// URLs,
|
||||
// tagged explicitly as a "file" opaque origin rather than a fully anonymous one.
|
||||
//
|
||||
// This keeps file:// URLs opaque by default while still allowing downstream code to
|
||||
// identify and special-case them where needed - for example, to match cases where
|
||||
// other browsers treat a file:// origin as if it were a tuple origin.
|
||||
//
|
||||
// A process-wide flag can opt into tuple origins for file:// URLs instead. This is
|
||||
// intended for development/testing scenarios where web features requiring a non-opaque
|
||||
// origin (such as localStorage) need to work with file:// pages.
|
||||
if (file_scheme_urls_have_tuple_origins())
|
||||
return Origin { scheme(), String {}, {} };
|
||||
|
||||
return Origin::create_opaque(Origin::OpaqueData::Type::File);
|
||||
}
|
||||
|
||||
// -> Otherwise
|
||||
|
||||
Reference in New Issue
Block a user