Truly independent web browser
LibWeb+LibWebView: Make top-level data: documents non-secure contexts
Zaggy1024ff90aee28719
diff --git a/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Libraries/LibWeb/HTML/Scripting/Environments.cppindex f23bf5555c3..42aa55c1b1d 100644--- a/Libraries/LibWeb/HTML/Scripting/Environments.cpp+++ b/Libraries/LibWeb/HTML/Scripting/Environments.cpp@@ -685,11 +685,15 @@ bool is_secure_context(Environment const& environment)return true;}- // 2. If the result of Is url potentially trustworthy? given environment's top-level creation URL is "Potentially Trustworthy", then return true.+ // 2. If environment's top-level creation URL's scheme is "data", then return false.+ if (environment.top_level_creation_url.value().scheme() == "data"sv)+ return false;++ // 3. If the result of Is url potentially trustworthy? given environment's top-level creation URL is "Potentially Trustworthy", then return true.if (SecureContexts::is_url_potentially_trustworthy(environment.top_level_creation_url.value()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy)return true;- // 3. Return false.+ // 4. Return false.return false;}diff --git a/Libraries/LibWebView/NavigationLoader.cpp b/Libraries/LibWebView/NavigationLoader.cppindex f6d4f253485..3f08087d720 100644--- a/Libraries/LibWebView/NavigationLoader.cpp+++ b/Libraries/LibWebView/NavigationLoader.cpp@@ -204,9 +204,11 @@ void NavigationLoader::obtain_the_response_policies(CanonicalNavigable const& naauto const& top_level_creation_url = navigable.is_top_level_traversable() ? response_url : navigable.top_level_traversable().active_document().creation_url();// https://html.spec.whatwg.org/multipage/webappapis.html#secure-context- // 2. If the result of Is url potentially trustworthy? given environment's top-level creation URL is "Potentially+ // 2. If environment's top-level creation URL's scheme is "data", then return false.+ // 3. If the result of Is url potentially trustworthy? given environment's top-level creation URL is "Potentially// Trustworthy", then return true.- auto reserved_environment_is_a_non_secure_context = Web::SecureContexts::is_url_potentially_trustworthy(top_level_creation_url) == Web::SecureContexts::Trustworthiness::NotTrustworthy;+ auto reserved_environment_is_a_non_secure_context = top_level_creation_url.scheme() == "data"sv+ || Web::SecureContexts::is_url_potentially_trustworthy(top_level_creation_url) == Web::SecureContexts::Trustworthiness::NotTrustworthy;// 9. Set responsePolicyContainer to the result of creating a policy container from a fetch response given// response and request's reserved client.diff --git a/Tests/LibWeb/Text/expected/secure-context-top-level-data-url.txt b/Tests/LibWeb/Text/expected/secure-context-top-level-data-url.txtnew file mode 100644index 00000000000..813cd6f76f6--- /dev/null+++ b/Tests/LibWeb/Text/expected/secure-context-top-level-data-url.txt@@ -0,0 +1,2 @@+https: true+data: falsediff --git a/Tests/LibWeb/Text/input/secure-context-top-level-data-url.html b/Tests/LibWeb/Text/input/secure-context-top-level-data-url.htmlnew file mode 100644index 00000000000..e6d10977aa3--- /dev/null+++ b/Tests/LibWeb/Text/input/secure-context-top-level-data-url.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<script src="include.js"></script>+<script>+ test(() => {+ internals.setEnvironmentsTopLevelURL("https://ladybird.org/");+ println(`https: ${isSecureContext}`);++ internals.setEnvironmentsTopLevelURL("data:text/html,");+ println(`data: ${isSecureContext}`);+ });+</script>