Truly independent web browser
LibWeb: Report no violations for a stand-in of a remote environment
Luke Wildeae8c84f9afa0
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cppindex 89d9215bef4..9731509f043 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp@@ -20,6 +20,7 @@#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/PolicyContainers.h>+#include <LibWeb/HTML/Scripting/EnvironmentSettingsSnapshot.h>#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Window.h>#include <LibWeb/TrustedTypes/RequireTrustedTypesForDirective.h>@@ -31,9 +32,22 @@namespace Web::ContentSecurityPolicy {+// AD-HOC: A client standing in for an environment another process hosts has its global object there, and its+// violations belong to that global, so none is reported here unless the client reports them to that process.+// FIXME: Report the violations of every such client in the process hosting its environment.+static bool may_report_violations_for(GC::Ptr<HTML::EnvironmentSettingsObject const> client)+{+ if (!client)+ return true;+ auto const* snapshot = as_if<HTML::EnvironmentSettingsSnapshot>(*client);+ return !snapshot || snapshot->report_violation();+}+ViolationReporter violation_reporter_for_request(JS::Realm& realm, GC::Ref<Fetch::Infrastructure::Request> request){return [&realm, request](NonnullRefPtr<Policy const> policy) {+ if (!may_report_violations_for(request->client()))+ return;auto violation = Violation::create_a_violation_object_for_request_and_policy(request, move(policy));violation->report_a_violation(realm);};@@ -55,16 +69,18 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_coif (directive_result == Directives::Directive::Result::Allowed)continue;- // 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s- // client’s global object, policy, and directive’s name.- auto& realm = navigation_request->client()->realm();- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());+ if (may_report_violations_for(navigation_request->client())) {+ // 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s+ // client’s global object, policy, and directive’s name.+ auto& realm = navigation_request->client()->realm();+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());- // 3. Set violation’s resource to navigation request’s URL.- violation->set_resource(navigation_request->url());+ // 3. Set violation’s resource to navigation request’s URL.+ violation->set_resource(navigation_request->url());- // 4. Execute § 5.5 Report a violation on violation.- violation->report_a_violation(realm);+ // 4. Execute § 5.5 Report a violation on violation.+ violation->report_a_violation(realm);+ }// 5. If policy’s disposition is "enforce", then set result to "Blocked".if (policy->disposition() == Policy::Disposition::Enforce)@@ -101,15 +117,17 @@ Directives::Directive::Result should_navigation_request_of_type_be_blocked_by_coif (Directives::inline_check(directive, nullptr, Directives::Directive::InlineType::Navigation, policy, serialized_url_utf16.utf16_view()) == Directives::Directive::Result::Allowed)continue;- // 3. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global,- // policy, and directive on navigation request’s client’s global object, policy, and directive-name.- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive_name.view().to_utf8_but_should_be_ported_to_utf16());+ if (may_report_violations_for(navigation_request->client())) {+ // 3. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global,+ // policy, and directive on navigation request’s client’s global object, policy, and directive-name.+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive_name.view().to_utf8_but_should_be_ported_to_utf16());- // 4. Set violation’s resource to "inline".- violation->set_resource(Violation::Resource::Inline);+ // 4. Set violation’s resource to "inline".+ violation->set_resource(Violation::Resource::Inline);- // 5. Execute § 5.5 Report a violation on violation.- violation->report_a_violation(realm);+ // 5. Execute § 5.5 Report a violation on violation.+ violation->report_a_violation(realm);+ }// 6. If policy’s disposition is "enforce", then set result to "Blocked".if (policy->disposition() == Policy::Disposition::Enforce)@@ -194,15 +212,17 @@ Directives::Directive::Result should_navigation_response_to_navigation_request_oif (directive_result == Directives::Directive::Result::Allowed)continue;- // 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s client’s global object, policy, and directive’s name.- auto& realm = navigation_request->client()->realm();- auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());+ if (may_report_violations_for(navigation_request->client())) {+ // 2. Otherwise, let violation be the result of executing § 2.4.1 Create a violation object for global, policy, and directive on navigation request’s client’s global object, policy, and directive’s name.+ auto& realm = navigation_request->client()->realm();+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(navigation_request->client()->global_object(), policy, directive.name().view().to_utf8_but_should_be_ported_to_utf16());- // 3. Set violation’s resource to navigation request’s URL.- violation->set_resource(navigation_request->url());+ // 3. Set violation’s resource to navigation request’s URL.+ violation->set_resource(navigation_request->url());- // 4. Execute § 5.5 Report a violation on violation.- violation->report_a_violation(realm);+ // 4. Execute § 5.5 Report a violation on violation.+ violation->report_a_violation(realm);+ }// 5. If policy’s disposition is "enforce", then set result to "Blocked".if (policy->disposition() == Policy::Disposition::Enforce)diff --git a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp b/Libraries/LibWeb/MixedContent/AbstractOperations.cppindex 44598a3ea52..e10069e1b09 100644--- a/Libraries/LibWeb/MixedContent/AbstractOperations.cpp+++ b/Libraries/LibWeb/MixedContent/AbstractOperations.cpp@@ -67,6 +67,8 @@ ProhibitsMixedSecurityContexts does_settings_prohibit_mixed_security_contexts(GCreturn ProhibitsMixedSecurityContexts::ProhibitsMixedSecurityContexts;// 2. If settings’ global object is a window, then:+ // FIXME: A settings object standing in for an environment another process hosts reads the global object it+ // borrows here, not the one of the environment it stands for.if (auto* window = HTML::window_from_global_object(settings->global_object())) {// 1. Set document to settings’ global object's associated Document.auto document = window->document();diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.txtnew file mode 100644index 00000000000..47fd9f90fb1--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.txt@@ -0,0 +1,4 @@+sibling navigated+WebContent#0+ iframe#0: remote WebContent#1+ iframe#1: remote WebContent#2diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.htmlnew file mode 100644index 00000000000..aaeece22d09--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.html@@ -0,0 +1,85 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // An isolated iframe's policy blocks its navigation of a sibling that another process hosts. The violation+ // belongs to the source iframe, so the document the sibling is showing sees no securitypolicyviolation event.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const runId = crypto.randomUUID();+ const targetHostname = uniqueLocalhostHostname("oop-violation-target");++ const echo = async (path, headers, body, hostname) => {+ const url = new URL(+ await httpServer.createEcho("GET", path, {+ status: 200,+ headers: { "Content-Type": "text/html", ...headers },+ body,+ })+ );+ url.hostname = hostname;+ return url;+ };++ const targetFirstUrl = await echo(+ `/oop-violation-target-first-${runId}`,+ {},+ `<!DOCTYPE html>first<script>+ document.addEventListener("securitypolicyviolation", () => top.postMessage("securitypolicyviolation fired in the sibling", "*"));+ <\/script>`,+ targetHostname+ );+ const targetSecondUrl = await echo(+ `/oop-violation-target-second-${runId}`,+ {},+ `<!DOCTYPE html><script>top.postMessage("sibling navigated", "*");<\/script>`,+ targetHostname+ );+ const blockedUrl = await echo(+ `/oop-violation-blocked-${runId}`,+ {},+ `<!DOCTYPE html><script>top.postMessage("blocked navigation went through", "*");<\/script>`,+ uniqueLocalhostHostname("oop-violation-blocked")+ );+ const sourceUrl = await echo(+ `/oop-violation-source-${runId}`,+ { "Content-Security-Policy": `frame-src ${targetSecondUrl.origin}` },+ `<!DOCTYPE html>+ <a id="blocked" target="target" href="${blockedUrl.href}">blocked</a>+ <a id="allowed" target="target" href="${targetSecondUrl.href}">allowed</a>+ <script>+ addEventListener("message", () => document.getElementById("allowed").click());+ document.getElementById("blocked").click();+ <\/script>`,+ uniqueLocalhostHostname("oop-violation-source")+ );++ const target = document.createElement("iframe");+ target.name = "target";+ target.src = targetFirstUrl;+ document.body.appendChild(target);+ await new Promise(resolve => (target.onload = resolve));++ const messages = [];+ const navigated = new Promise(resolve => {+ addEventListener("message", event => {+ messages.push(event.data);+ if (event.data === "sibling navigated")+ resolve();+ });+ });+ const blockedNavigationLoaded = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));++ const source = document.createElement("iframe");+ source.src = sourceUrl;+ document.body.appendChild(source);++ // The source navigates the sibling again only once its blocked navigation has finished.+ await blockedNavigationLoaded;+ source.contentWindow.postMessage("navigate the sibling", "*");+ await navigated;++ for (const message of messages)+ println(message);+ println(internals.dumpSiteIsolationProcessTree().trimEnd());+ });+</script>