Skip to content

Truly independent web browser

LibWeb+LibWebView: Check iframe navigations against the container CSP

sideshowbarkerd1fa652e414e
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
index c15c7ff571d..579b40db3d0 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/BlockingAlgorithms.cpp
@@ -78,9 +78,44 @@ static void report_a_violation_of_a_remote_client(Page& page, Fetch::Infrastruct
page.client().page_did_report_violation_of_remote_client(*policy_index, directive.view().to_utf8_but_should_be_ported_to_utf16(), request.url());
}
+// AD-HOC: A child navigable's navigation violates a policy of its container's node document, whose global object the
+// violation is reported on. See https://github.com/w3c/webappsec-csp/issues/624.
+static void report_a_violation_of_a_container_document(Page& page, Fetch::Infrastructure::Request const& request, Fetch::Infrastructure::Request::ChildNavigableNavigation const& navigation, Policy const& policy)
+{
+ auto effective_directive = Directives::get_the_effective_directive_for_request(request);
+ VERIFY(effective_directive.has_value());
+
+ // NB: The request's copy of the container document's CSP list lists the policies in the same order.
+ auto const& policies = navigation.container_document_csp_list.policies();
+ auto policy_index = policies.find_first_index_if([&](auto const& candidate) { return candidate.ptr() == &policy; });
+ VERIFY(policy_index.has_value());
+
+ auto navigable = page.navigable_with_id(navigation.navigable_id);
+ if (auto container_document = navigable ? navigable->container_document() : nullptr) {
+ auto& settings = container_document->relevant_settings_object();
+ auto violation = Violation::create_a_violation_object_for_global_policy_and_directive(settings.global_object(), policy, String { effective_directive->view().to_utf8_but_should_be_ported_to_utf16() });
+ violation->set_resource(request.url());
+ violation->report_a_violation(settings.realm());
+ return;
+ }
+
+ // NB: A container document in another process gets the report through the UI process, which checks it against the
+ // directives the navigation can violate, and reports the URL the navigation started with, upgraded to https
+ // when the request's URL is.
+ auto remote_directive = remote_violation_directive(*effective_directive);
+ if (!navigation.navigation_id.has_value() || !remote_directive.has_value())
+ return;
+ auto url_is_https = request.url().scheme() == "https"sv;
+ page.client().page_did_report_navigation_violation_of_container_document(navigation.navigable_id, *navigation.navigation_id, *policy_index, *remote_directive, url_is_https);
+}
+
ViolationReporter violation_reporter_for_request(JS::Realm& realm, NonnullRefPtr<Fetch::Infrastructure::Request> request)
{
return [&realm, request](NonnullRefPtr<Policy const> policy) {
+ if (auto const& navigation = request->child_navigable_navigation(); navigation.has_value()) {
+ report_a_violation_of_a_container_document(Bindings::principal_host_defined_page(realm), request, *navigation, policy);
+ return;
+ }
if (Fetch::Fetching::remote_client(request)) {
auto effective_directive = Directives::get_the_effective_directive_for_request(request);
VERIFY(effective_directive.has_value());
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/FetchIntegration.cpp b/Libraries/LibWeb/ContentSecurityPolicy/FetchIntegration.cpp
index f3efd21e81f..bbb36a06fa4 100644
--- a/Libraries/LibWeb/ContentSecurityPolicy/FetchIntegration.cpp
+++ b/Libraries/LibWeb/ContentSecurityPolicy/FetchIntegration.cpp
@@ -68,11 +68,21 @@ namespace Web::ContentSecurityPolicy {
return violates;
}
+// AD-HOC: A child navigable's navigation is governed by the CSP list of its container's node document, rather than by
+// that of request's policy container, which is its source document's.
+// See https://github.com/w3c/webappsec-csp/issues/624.
+static PolicyList const& csp_list_governing_request(Fetch::Infrastructure::Request const& request)
+{
+ if (auto const& navigation = request.child_navigable_navigation(); navigation.has_value())
+ return navigation->container_document_csp_list;
+ return request.policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list;
+}
+
// https://w3c.github.io/webappsec-csp/#report-for-request
void report_content_security_policy_violations_for_request(Fetch::Infrastructure::Request const& request, ViolationReporter const& report_violation)
{
// 1. Let CSP list be request’s policy container's CSP list.
- auto const& csp_list = request.policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list;
+ auto const& csp_list = csp_list_governing_request(request);
// 2. For each policy of CSP list:
for (auto const& policy : csp_list.policies()) {
@@ -94,7 +104,7 @@ void report_content_security_policy_violations_for_request(Fetch::Infrastructure
Directives::Directive::Result should_request_be_blocked_by_content_security_policy(Fetch::Infrastructure::Request const& request, ViolationReporter const& report_violation)
{
// 1. Let CSP list be request’s policy container's CSP list.
- auto const& csp_list = request.policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list;
+ auto const& csp_list = csp_list_governing_request(request);
// 2. Let result be "Allowed".
auto result = Directives::Directive::Result::Allowed;
@@ -127,7 +137,7 @@ Directives::Directive::Result should_request_be_blocked_by_content_security_poli
Directives::Directive::Result should_response_to_request_be_blocked_by_content_security_policy(Fetch::Infrastructure::Response const& response, Fetch::Infrastructure::Request const& request, ViolationReporter const& report_violation)
{
// 1. Let CSP list be request’s policy container's CSP list.
- auto const& csp_list = request.policy_container().get<NonnullRefPtr<HTML::PolicyContainer const>>()->csp_list;
+ auto const& csp_list = csp_list_governing_request(request);
// 2. Let result be "Allowed".
auto result = Directives::Directive::Result::Allowed;
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
index 11c1babb512..fea514a76c8 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.cpp
@@ -259,6 +259,7 @@ NonnullRefPtr<Request> Request::clone() const
new_request->set_client(m_client);
new_request->set_client_snapshot(m_client_snapshot);
new_request->set_remote_client_navigation(m_remote_client_navigation);
+ new_request->set_child_navigable_navigation(m_child_navigable_navigation);
new_request->set_reserved_client_snapshot(m_reserved_client_snapshot);
new_request->set_replaces_client_id(m_replaces_client_id);
new_request->set_traversable_for_user_prompts(m_traversable_for_user_prompts);
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
index ffc251545c0..5a21a7183ad 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Requests.h
@@ -25,6 +25,7 @@
#include <LibHTTP/HeaderList.h>
#include <LibURL/Origin.h>
#include <LibURL/URL.h>
+#include <LibWeb/ContentSecurityPolicy/PolicyList.h>
#include <LibWeb/Export.h>
#include <LibWeb/Fetch/Infrastructure/ClientContextSnapshot.h>
#include <LibWeb/Fetch/Infrastructure/HTTP.h>
@@ -202,6 +203,14 @@ public:
[[nodiscard]] Optional<HTML::RemoteClientNavigation> const& remote_client_navigation() const { return m_remote_client_navigation; }
void set_remote_client_navigation(Optional<HTML::RemoteClientNavigation> remote_client_navigation) { m_remote_client_navigation = move(remote_client_navigation); }
+ struct ChildNavigableNavigation {
+ HTML::CrossProcessId navigable_id;
+ Optional<Utf16String> navigation_id;
+ ContentSecurityPolicy::PolicyList container_document_csp_list;
+ };
+ [[nodiscard]] Optional<ChildNavigableNavigation> const& child_navigable_navigation() const { return m_child_navigable_navigation; }
+ void set_child_navigable_navigation(Optional<ChildNavigableNavigation> child_navigable_navigation) { m_child_navigable_navigation = move(child_navigable_navigation); }
+
[[nodiscard]] RefPtr<ReservedClientContextSnapshot const> const& reserved_client_snapshot() const { return m_reserved_client_snapshot; }
void set_reserved_client_snapshot(RefPtr<ReservedClientContextSnapshot const> reserved_client_snapshot) { m_reserved_client_snapshot = move(reserved_client_snapshot); }
@@ -391,6 +400,12 @@ private:
// client.
Optional<HTML::RemoteClientNavigation> m_remote_client_navigation;
+ // AD-HOC: The navigation of a navigation request whose navigable is a child navigable, with a copy of the CSP list
+ // of the navigable's container's node document. That document's frame-src governs where the
+ // navigable can be navigated to, whichever document started the navigation.
+ // See https://github.com/w3c/webappsec-csp/issues/624.
+ Optional<ChildNavigableNavigation> m_child_navigable_navigation;
+
// https://fetch.spec.whatwg.org/#concept-request-reserved-client
// A request has an associated reserved client (null, an environment, or an environment settings object). Unless
// stated otherwise it is null.
diff --git a/Libraries/LibWeb/HTML/HTMLMetaElement.cpp b/Libraries/LibWeb/HTML/HTMLMetaElement.cpp
index 9167f9bbfc4..22549dc6728 100644
--- a/Libraries/LibWeb/HTML/HTMLMetaElement.cpp
+++ b/Libraries/LibWeb/HTML/HTMLMetaElement.cpp
@@ -233,10 +233,10 @@ void HTMLMetaElement::inserted()
// 5. Enforce the policy policy.
document().relevant_settings_object().policy_container()->csp_list.enforce_policy(policy);
- // NB: A document created in a child navigable inherits the insecure requests policy of its container's
- // node document, which a process hosting the child navigable reads from the container's state.
- if (policy->contains_directive_with_name(ContentSecurityPolicy::Directives::Names::UpgradeInsecureRequests))
- report_container_state_of_child_navigables(document());
+ // NB: A process hosting a child navigable reads its container's node document's CSP list from the
+ // container's state: Its frame-src governs where the child navigable can be navigated to, and a
+ // document created in the child navigable inherits its insecure requests policy.
+ report_container_state_of_child_navigables(document());
break;
}
default:
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 469c9ee0726..2fa483fc7c1 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -2775,6 +2775,19 @@ static void create_navigation_params_by_fetching(
request->set_initiator_type(container_is_iframe ? Web::Fetch::Infrastructure::Request::InitiatorType::IFrame
: Web::Fetch::Infrastructure::Request::InitiatorType::Object);
}
+
+ // AD-HOC: The navigable's container's node document's frame-src governs where the navigable can be navigated
+ // to, rather than that of the source document, which isn't the container document when, e.g., the
+ // navigable's own document navigates it. See https://github.com/w3c/webappsec-csp/issues/624.
+ // NB: A container document in another process is not here, so its CSP list is read from the container's state.
+ auto container_document = navigable->container_document();
+ request->set_child_navigable_navigation(Fetch::Infrastructure::Request::ChildNavigableNavigation {
+ .navigable_id = navigable->id(),
+ .navigation_id = navigation_id,
+ .container_document_csp_list = container_document
+ ? container_document->policy_container()->csp_list
+ : ContentSecurityPolicy::PolicyList { navigable->container_state().document_csp_list },
+ });
}
// NOTE: We use a heap-allocated cell to hold all the following state because the callbacks below will use them
diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp
index 81a99f4f06d..cf0b15a1179 100644
--- a/Libraries/LibWeb/HTML/NavigableContainer.cpp
+++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp
@@ -636,6 +636,7 @@ ReplicatedContainerState NavigableContainer::replicated_container_state()
auto document_policy_container = document().policy_container();
state.document_insecure_requests_policy = document_policy_container->insecure_requests_policy();
state.document_upgrade_insecure_navigations_set = document_policy_container->upgrade_insecure_navigations_set();
+ state.document_csp_list = document_policy_container->csp_list.serialize();
state.used_color_scheme = m_used_color_scheme;
return state;
}
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 74376e9098b..db72ebb5d8f 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -1035,6 +1035,7 @@ public:
virtual void page_did_report_violation_of_remote_client([[maybe_unused]] u64 policy_index, [[maybe_unused]] String effective_directive, [[maybe_unused]] URL::URL resource) { }
// A navigation whose source another process hosts violated the policy at policy_index in the source's CSP list.
virtual void page_did_report_navigation_violation_of_remote_client([[maybe_unused]] HTML::RemoteClientNavigation const& navigation, [[maybe_unused]] u64 policy_index, [[maybe_unused]] ContentSecurityPolicy::RemoteViolationDirective directive, [[maybe_unused]] bool url_is_https) { }
+ virtual void page_did_report_navigation_violation_of_container_document([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] Utf16String const& navigation_id, [[maybe_unused]] u64 policy_index, [[maybe_unused]] ContentSecurityPolicy::RemoteViolationDirective directive, [[maybe_unused]] bool url_is_https) { }
virtual void page_did_register_javascript_source([[maybe_unused]] DOM::Document&, [[maybe_unused]] HTML::ScriptRegistry::Description const&) { }
virtual void page_did_post_broadcast_channel_message([[maybe_unused]] HTML::PostedBroadcastChannelMessage const& message) { }
virtual void page_did_close_shared_worker() { }
diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
index 5b4941e507b..e38460f7aef 100644
--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.cpp
@@ -25,6 +25,7 @@ ErrorOr<void> encode(Encoder& encoder, Web::HTML::ReplicatedContainerState const
TRY(Web::PermissionsPolicy::encode_policy_directive(encoder, state.container_policy));
TRY(encoder.encode(state.document_insecure_requests_policy));
TRY(encoder.encode(state.document_upgrade_insecure_navigations_set));
+ TRY(encoder.encode(state.document_csp_list));
TRY(encoder.encode(to_underlying(state.used_color_scheme)));
return {};
}
@@ -53,6 +54,7 @@ ErrorOr<Web::HTML::ReplicatedContainerState> decode(Decoder& decoder)
.container_policy = TRY(Web::PermissionsPolicy::decode_policy_directive(decoder)),
.document_insecure_requests_policy = TRY(decoder.decode<Web::UpgradeInsecureRequests::InsecureRequestsPolicy>()),
.document_upgrade_insecure_navigations_set = TRY(decoder.decode<Web::UpgradeInsecureRequests::UpgradeInsecureNavigationsSet>()),
+ .document_csp_list = TRY(decoder.decode<Vector<Web::ContentSecurityPolicy::SerializedPolicy>>()),
.used_color_scheme = TRY(decode_used_color_scheme(decoder)),
};
}
diff --git a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
index 4a2978a58bf..c44be160345 100644
--- a/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
+++ b/Libraries/LibWebCommon/HTML/ReplicatedNavigableState.h
@@ -13,6 +13,7 @@
#include <LibURL/Origin.h>
#include <LibURL/URL.h>
#include <LibWebCommon/CSS/PreferredColorScheme.h>
+#include <LibWebCommon/ContentSecurityPolicy/SerializedPolicy.h>
#include <LibWebCommon/Export.h>
#include <LibWebCommon/HTML/CrossOrigin/OpenerPolicy.h>
#include <LibWebCommon/HTML/CrossProcessId.h>
@@ -66,6 +67,10 @@ struct ReplicatedContainerState {
// node document's policy container.
UpgradeInsecureRequests::UpgradeInsecureNavigationsSet document_upgrade_insecure_navigations_set {};
+ // https://html.spec.whatwg.org/multipage/browsers.html#policy-container-csp-list, of the container's node
+ // document's policy container, whose frame-src governs where the navigable can be navigated to.
+ Vector<ContentSecurityPolicy::SerializedPolicy> document_csp_list {};
+
// https://drafts.csswg.org/css-color-adjust-1/#color-scheme-effect
// The container's used color scheme, which decides whether the canvas of the navigable's document is opaque.
CSS::PreferredColorScheme used_color_scheme { CSS::PreferredColorScheme::Light };
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index e8bdc26def6..9f59b094728 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -781,6 +781,20 @@ static bool navigation_can_violate(Web::ContentSecurityPolicy::RemoteViolationDi
VERIFY_NOT_REACHED();
}
+// The request's URL can be upgraded from http to https before the check, by upgrade-insecure-requests or HSTS, so the
+// report then names the upgraded URL.
+static URL::URL reported_navigation_url(Web::HTML::NavigationPopulationRequest const& request, bool url_is_https)
+{
+ auto url = request.history_entry.url;
+ if (url_is_https && url.scheme() == "http"sv) {
+ url.set_scheme("https"_string);
+ // NB: Unlike the URL parser, setting the scheme does not remove a port that is the new scheme's default port.
+ if (url.port() == 443)
+ url.set_port({});
+ }
+ return url;
+}
+
// The process populating a navigation reports a violation of a policy of its source, which goes to the page found
// hosting the source when the navigation was requested, while that page still hosts it.
void WebContentPage::did_report_navigation_violation(Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective directive, bool url_is_https)
@@ -804,16 +818,36 @@ void WebContentPage::did_report_navigation_violation(Web::HTML::CrossProcessId n
if (!source_page || !source_page->is_open() || !source_page->hosted_environment(fetch_client->id).has_value())
return;
- // The request's URL can be upgraded from http to https before the check, by upgrade-insecure-requests or HSTS, so
- // the report then names the upgraded URL.
- auto url = request.history_entry.url;
- if (url_is_https && url.scheme() == "http"sv) {
- url.set_scheme("https"_string);
- // NB: Unlike the URL parser, setting the scheme does not remove a port that is the new scheme's default port.
- if (url.port() == 443)
- url.set_port({});
+ source_page->async_report_violation_of_environment(fetch_client->id, policy_index, directive, reported_navigation_url(request, url_is_https));
+}
+
+// The process populating a child navigable's navigation reports a violation of a policy of the navigable's container's
+// node document, which goes to the page hosting that document.
+void WebContentPage::did_report_container_document_navigation_violation(Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective directive, bool url_is_https)
+{
+ auto navigable = population_worker_navigable(navigable_id);
+ if (!navigable.has_value())
+ return;
+ auto navigation = navigable->navigation_with_id(navigation_id);
+ auto* creating = navigation ? navigation->state.get_pointer<CanonicalNavigation::CreatingNavigationParams>() : nullptr;
+ if (!creating || navigation->worker() != this)
+ return;
+
+ auto const& request = creating->loader->request();
+ if (directive == Web::ContentSecurityPolicy::RemoteViolationDirective::FormAction || !navigation_can_violate(directive, *navigable, request)) {
+ client().did_misbehave("did_report_container_document_navigation_violation"sv, "violation the navigation cannot have"sv);
+ return;
}
- source_page->async_report_violation_of_environment(fetch_client->id, policy_index, directive, move(url));
+
+ auto* container_document = navigable->container_document();
+ if (!container_document)
+ return;
+ auto const& host = container_document->host();
+ if (!host || !host->is_open())
+ return;
+
+ auto const& environment_id = container_document->relevant_global_object().relevant_settings_object().id();
+ host->async_report_violation_of_environment(environment_id, policy_index, directive, reported_navigation_url(request, url_is_https));
}
void WebContentPage::did_post_message_to_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor posted_message)
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 9a9a1bd3302..8fffe24f172 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -205,6 +205,7 @@ private:
virtual void did_request_navigation_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::CrossProcessId source_document_id, Web::HTML::PreparedNavigationDescriptor navigation) override;
virtual void did_post_message_to_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor posted_message) override;
virtual void did_report_navigation_violation(Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective, bool url_is_https) override;
+ virtual void did_report_container_document_navigation_violation(Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective, bool url_is_https) override;
virtual void did_request_focusing_steps_for_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) override;
virtual void did_request_window_focus_of_navigable(Web::HTML::CrossProcessId navigable_id) override;
virtual void did_request_set_opener_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId opener_navigable_id) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index 6736613d818..c416ac0ba48 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -1767,6 +1767,11 @@ void PageClient::page_did_report_navigation_violation_of_remote_client(Web::HTML
client().async_did_report_navigation_violation(m_id, navigation.navigable_id, navigation.navigation_id, policy_index, directive, url_is_https);
}
+void PageClient::page_did_report_navigation_violation_of_container_document(Web::HTML::CrossProcessId navigable_id, Utf16String const& navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective directive, bool url_is_https)
+{
+ client().async_did_report_container_document_navigation_violation(m_id, navigable_id, navigation_id, policy_index, directive, url_is_https);
+}
+
void PageClient::page_did_update_resource_count(i32 count_waiting)
{
client().async_did_update_resource_count(m_id, count_waiting);
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index a7379ad4373..4cd9e5fb4f5 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -439,6 +439,7 @@ private:
virtual void page_did_register_javascript_source(Web::DOM::Document&, Web::HTML::ScriptRegistry::Description const&) override;
virtual void page_did_post_broadcast_channel_message(Web::HTML::PostedBroadcastChannelMessage const&) override;
virtual void page_did_report_navigation_violation_of_remote_client(Web::HTML::RemoteClientNavigation const&, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective, bool url_is_https) override;
+ virtual void page_did_report_navigation_violation_of_container_document(Web::HTML::CrossProcessId navigable_id, Utf16String const& navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective, bool url_is_https) override;
void setup_palette();
ConnectionFromClient& client() const;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index dd361dd47e7..f15258d9c24 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -95,6 +95,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_request_navigation_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::CrossProcessId source_document_id, Web::HTML::PreparedNavigationDescriptor navigation) =|
did_post_message_to_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message) =|
did_report_navigation_violation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective directive, bool url_is_https) =|
+ did_report_container_document_navigation_violation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id, u64 policy_index, Web::ContentSecurityPolicy::RemoteViolationDirective directive, bool url_is_https) =|
did_request_close_of_traversable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::NavigationSourceSnapshot source_snapshot) =|
did_request_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) =|
did_request_window_focus_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
diff --git a/Tests/LibWeb/Text/expected/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.txt b/Tests/LibWeb/Text/expected/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.txt
new file mode 100644
index 00000000000..944e483d5cc
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.txt
@@ -0,0 +1,3 @@
+A child whose own policy allows no frames navigated itself
+The container navigated a child whose own policy allows no frames
+securitypolicyviolation in the container: frame-src, blocked URL matches: true
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.txt
deleted file mode 100644
index 47fd9f90fb1..00000000000
--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-sibling navigated
-WebContent#0
- iframe#0: remote WebContent#1
- iframe#1: remote WebContent#2
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.txt
new file mode 100644
index 00000000000..dab3ead544b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.txt
@@ -0,0 +1,6 @@
+securitypolicyviolation in the container: frame-src, disposition: enforce, blocked URL matches: true, document URL matches: true
+sibling navigated
+WebContent#0
+ iframe#0: remote WebContent#1
+ iframe#0: remote WebContent#2
+ iframe#1: remote WebContent#3
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.txt
deleted file mode 100644
index 6d7f31911a4..00000000000
--- a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-securitypolicyviolation in the source: frame-src, disposition: enforce, blocked URL matches: true, document URL matches: true
-sibling navigated
-WebContent#0
- iframe#0: remote WebContent#1
- iframe#1: remote WebContent#2
diff --git a/Tests/LibWeb/Text/input/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.html b/Tests/LibWeb/Text/input/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.html
new file mode 100644
index 00000000000..f3f7215b77a
--- /dev/null
+++ b/Tests/LibWeb/Text/input/ContentSecurityPolicy/frame-src-of-the-container-governs-child-navigation.html
@@ -0,0 +1,119 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<script>
+ // An iframe's navigation is checked against the frame-src of its container document, whichever document starts the
+ // navigation, and never against the iframe's own document's. A violation is reported in the container document.
+ promiseTest(async () => {
+ const httpServer = httpTestServer();
+ const runId = uniqueID();
+ const hostname = uniqueLocalhostHostname("container-frame-src");
+
+ const echo = async (path, headers, body, echoHostname = hostname) => {
+ const url = new URL(
+ await httpServer.createEcho("GET", path, {
+ status: 200,
+ headers: { "Content-Type": "text/html", ...headers },
+ body,
+ })
+ );
+ url.hostname = echoHostname;
+ return url;
+ };
+
+ const reportLoad = name => `<!DOCTYPE html><script>parent.postMessage("${name} loaded", "*");<\/script>`;
+ const allowedUrl = await echo(`/container-frame-src-allowed-${runId}`, {}, reportLoad("allowed"));
+ const blockedUrl = await echo(
+ `/container-frame-src-blocked-${runId}`,
+ {},
+ reportLoad("blocked"),
+ uniqueLocalhostHostname("container-frame-src-blocked")
+ );
+
+ // A document whose own policy allows no frames at all, which navigates itself when asked to.
+ const childUrl = await echo(
+ `/container-frame-src-child-${runId}`,
+ { "Content-Security-Policy": "default-src 'none'; script-src 'unsafe-inline'" },
+ `<!DOCTYPE html><script>
+ document.addEventListener("securitypolicyviolation", event => {
+ parent.postMessage("securitypolicyviolation in the child: " + event.effectiveDirective, "*");
+ });
+ addEventListener("message", event => (location.href = event.data));
+ parent.postMessage("child loaded", "*");
+ <\/script>`
+ );
+
+ const containerUrl = await echo(
+ `/container-frame-src-container-${runId}`,
+ { "Content-Security-Policy": "frame-src 'self'" },
+ `<!DOCTYPE html><body><script>
+ let violationReported;
+ const reported = new Promise(resolve => (violationReported = resolve));
+ document.addEventListener("securitypolicyviolation", event => {
+ top.postMessage(
+ "securitypolicyviolation in the container: " + event.effectiveDirective
+ + ", blocked URL matches: " + (event.blockedURI === "${blockedUrl.href}"),
+ "*"
+ );
+ violationReported();
+ });
+
+ const nextMessage = expected => new Promise(resolve => {
+ addEventListener("message", function receive(event) {
+ if (!event.data.endsWith(expected)) {
+ top.postMessage(event.data, "*");
+ return;
+ }
+ removeEventListener("message", receive);
+ resolve();
+ });
+ });
+ const loadChild = async () => {
+ const child = document.createElement("iframe");
+ const loaded = nextMessage("child loaded");
+ child.src = "${childUrl.href}";
+ document.body.appendChild(child);
+ await loaded;
+ return child;
+ };
+
+ (async () => {
+ let child = await loadChild();
+ let loaded = nextMessage("allowed loaded");
+ child.contentWindow.postMessage("${allowedUrl.href}", "*");
+ await loaded;
+ top.postMessage("A child whose own policy allows no frames navigated itself", "*");
+
+ child = await loadChild();
+ loaded = nextMessage("allowed loaded");
+ child.src = "${allowedUrl.href}";
+ await loaded;
+ top.postMessage("The container navigated a child whose own policy allows no frames", "*");
+
+ child = await loadChild();
+ loaded = new Promise(resolve => child.addEventListener("load", resolve, { once: true }));
+ child.contentWindow.postMessage("${blockedUrl.href}", "*");
+ await Promise.all([loaded, reported]);
+ top.postMessage("done", "*");
+ })();
+ <\/script>`
+ );
+
+ const messages = [];
+ const done = new Promise(resolve => {
+ addEventListener("message", event => {
+ if (event.data === "done")
+ resolve();
+ else
+ messages.push(event.data);
+ });
+ });
+
+ const container = document.createElement("iframe");
+ container.src = containerUrl;
+ document.body.appendChild(container);
+ await done;
+
+ for (const message of messages)
+ println(message);
+ });
+</script>
diff --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.html
deleted file mode 100644
index aaeece22d09..00000000000
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-not-reported-in-the-frame-it-navigates.html
+++ /dev/null
@@ -1,85 +0,0 @@
-<!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>
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.html
new file mode 100644
index 00000000000..d3a98873742
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-container.html
@@ -0,0 +1,115 @@
+<!DOCTYPE html>
+<script src="../../include.js"></script>
+<script>
+ // An isolated iframe navigates its sibling, which another process hosts, somewhere the frame-src of their container
+ // document blocks. The process fetching for the sibling finds the violation, and the container document, in a third
+ // process, sees it as a securitypolicyviolation event. Neither the source nor the sibling sees one.
+ promiseTest(async () => {
+ const httpServer = httpTestServer();
+ const runId = uniqueID();
+ const targetHostname = uniqueLocalhostHostname("reported-violation-target");
+ const sourceHostname = uniqueLocalhostHostname("reported-violation-source");
+
+ 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(
+ `/reported-violation-target-first-${runId}`,
+ {},
+ `<!DOCTYPE html>first<script>
+ document.addEventListener("securitypolicyviolation", () => top.postMessage("securitypolicyviolation fired in the sibling", "*"));
+ <\/script>`,
+ targetHostname
+ );
+ const targetSecondUrl = await echo(
+ `/reported-violation-target-second-${runId}`,
+ {},
+ `<!DOCTYPE html><script>top.postMessage("sibling navigated", "*");<\/script>`,
+ targetHostname
+ );
+ const blockedUrl = await echo(
+ `/reported-violation-blocked-${runId}`,
+ {},
+ `<!DOCTYPE html><script>top.postMessage("blocked navigation went through", "*");<\/script>`,
+ uniqueLocalhostHostname("reported-violation-blocked")
+ );
+ const sourceUrl = await echo(
+ `/reported-violation-source-${runId}`,
+ {},
+ `<!DOCTYPE html>
+ <a id="blocked" target="target" href="${blockedUrl.href}">blocked</a>
+ <a id="allowed" target="target" href="${targetSecondUrl.href}">allowed</a>
+ <script>
+ document.addEventListener("securitypolicyviolation", () => top.postMessage("securitypolicyviolation fired in the source", "*"));
+ addEventListener("message", () => document.getElementById("allowed").click());
+ document.getElementById("blocked").click();
+ <\/script>`,
+ sourceHostname
+ );
+ const containerUrl = await echo(
+ `/reported-violation-container-${runId}`,
+ { "Content-Security-Policy": `frame-src ${targetFirstUrl.origin} ${sourceUrl.origin}` },
+ `<!DOCTYPE html>
+ <iframe name="target" src="${targetFirstUrl.href}"></iframe>
+ <script>
+ let reported = false;
+ let blockedNavigationLoaded = false;
+ let source;
+ const navigateTheSiblingAgain = () => {
+ if (reported && blockedNavigationLoaded)
+ source.contentWindow.postMessage("navigate the sibling", "*");
+ };
+ document.addEventListener("securitypolicyviolation", event => {
+ top.postMessage([
+ "securitypolicyviolation in the container: " + event.effectiveDirective,
+ "disposition: " + event.disposition,
+ "blocked URL matches: " + (event.blockedURI === "${blockedUrl.href}"),
+ "document URL matches: " + (event.documentURI === location.href),
+ ].join(", "), "*");
+ reported = true;
+ navigateTheSiblingAgain();
+ });
+ const target = document.querySelector("iframe");
+ target.onload = () => {
+ // The source navigates the sibling again only once its blocked navigation has finished.
+ target.onload = () => {
+ target.onload = null;
+ blockedNavigationLoaded = true;
+ navigateTheSiblingAgain();
+ };
+ source = document.createElement("iframe");
+ source.src = "${sourceUrl.href}";
+ document.body.appendChild(source);
+ };
+ <\/script>`,
+ uniqueLocalhostHostname("reported-violation-container")
+ );
+
+ const messages = [];
+ const navigated = new Promise(resolve => {
+ addEventListener("message", event => {
+ messages.push(event.data);
+ if (event.data === "sibling navigated")
+ resolve();
+ });
+ });
+
+ const container = document.createElement("iframe");
+ container.src = containerUrl;
+ document.body.appendChild(container);
+ await navigated;
+
+ for (const message of messages)
+ println(message);
+ println(internals.dumpSiteIsolationProcessTree().trimEnd());
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.html
deleted file mode 100644
index 93d28398c59..00000000000
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-is-reported-in-the-source.html
+++ /dev/null
@@ -1,91 +0,0 @@
-<!DOCTYPE html>
-<script src="../../include.js"></script>
-<script>
- // An isolated iframe's frame-src blocks its navigation of a sibling that another process hosts. The process
- // fetching for the sibling finds the violation, and the source iframe sees it as a securitypolicyviolation event.
- promiseTest(async () => {
- const httpServer = httpTestServer();
- const runId = uniqueID();
- const targetHostname = uniqueLocalhostHostname("reported-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(`/reported-violation-target-first-${runId}`, {}, "<!DOCTYPE html>first", targetHostname);
- const targetSecondUrl = await echo(
- `/reported-violation-target-second-${runId}`,
- {},
- `<!DOCTYPE html><script>top.postMessage("sibling navigated", "*");<\/script>`,
- targetHostname
- );
- const blockedUrl = await echo(
- `/reported-violation-blocked-${runId}`,
- {},
- `<!DOCTYPE html><script>top.postMessage("blocked navigation went through", "*");<\/script>`,
- uniqueLocalhostHostname("reported-violation-blocked")
- );
- const sourceUrl = await echo(
- `/reported-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>
- document.addEventListener("securitypolicyviolation", event => {
- top.postMessage([
- "securitypolicyviolation in the source: " + event.effectiveDirective,
- "disposition: " + event.disposition,
- "blocked URL matches: " + (event.blockedURI === "${blockedUrl.href}"),
- "document URL matches: " + (event.documentURI === location.href),
- ].join(", "), "*");
- });
- addEventListener("message", () => document.getElementById("allowed").click());
- document.getElementById("blocked").click();
- <\/script>`,
- uniqueLocalhostHostname("reported-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 = [];
- let violationReported;
- const reported = new Promise(resolve => (violationReported = resolve));
- const navigated = new Promise(resolve => {
- addEventListener("message", event => {
- messages.push(event.data);
- if (event.data.startsWith("securitypolicyviolation"))
- violationReported();
- 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 reported;
- await blockedNavigationLoaded;
- source.contentWindow.postMessage("navigate the sibling", "*");
- await navigated;
-
- for (const message of messages)
- println(message);
- println(internals.dumpSiteIsolationProcessTree().trimEnd());
- });
-</script>
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-names-the-navigations-url.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-names-the-navigations-url.html
index 3667e808f02..a4cfb6e7357 100644
--- a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-names-the-navigations-url.html
+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-csp-violation-names-the-navigations-url.html
@@ -1,8 +1,9 @@
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
- // A violation that the process fetching for an isolated sibling finds names the URL the navigation started with:
- // not a later redirect's, and upgraded to https when the source's upgrade-insecure-requests upgrades it.
+ // A violation that the process fetching for an isolated iframe finds, of its container document's frame-src, names
+ // the URL the navigation started with: not a later redirect's, and upgraded to https when the upgrade-insecure-requests
+ // of the sibling that started the navigation upgrades it.
promiseTest(async () => {
const httpServer = httpTestServer();
const runId = uniqueID();
@@ -13,7 +14,7 @@
url.hostname = hostname;
return url;
};
- const html = body => ({ status: 200, headers: { "Content-Type": "text/html" }, body });
+ const html = (body, headers = {}) => ({ status: 200, headers: { "Content-Type": "text/html", ...headers }, body });
const targetUrl = await echo(`/named-violation-target-${runId}`, html("<!DOCTYPE html>target"), targetHostname);
const blockedUrl = await echo(
@@ -27,32 +28,42 @@
targetHostname
);
- const target = document.createElement("iframe");
- target.name = "target";
- target.src = targetUrl;
- document.body.appendChild(target);
- await new Promise(resolve => (target.onload = resolve));
-
const messages = [];
addEventListener("message", event => messages.push(event.data));
- // The source navigates the sibling once, and posts the blocked URL of each violation it sees.
- const blockedURIOfNavigation = async (name, policy, href) => {
+ // The source navigates its sibling once, and the container posts the blocked URL of each violation it sees.
+ const blockedURIOfNavigation = async (name, sourcePolicy, href) => {
+ const sourceHeaders = sourcePolicy ? { "Content-Security-Policy": sourcePolicy } : {};
const sourceUrl = await echo(
`/named-violation-source-${name}-${runId}`,
- {
- status: 200,
- headers: { "Content-Type": "text/html", "Content-Security-Policy": policy },
- body: `<!DOCTYPE html>
+ html(
+ `<!DOCTYPE html>
<a id="navigate" target="target" href="${href}">navigate</a>
+ <script>document.getElementById("navigate").click();<\/script>`,
+ sourceHeaders
+ ),
+ uniqueLocalhostHostname(`named-violation-source-${name}`)
+ );
+ const containerUrl = await echo(
+ `/named-violation-container-${name}-${runId}`,
+ html(
+ `<!DOCTYPE html>
+ <iframe name="target" src="${targetUrl.href}"></iframe>
<script>
document.addEventListener("securitypolicyviolation", event => {
top.postMessage({ name: "${name}", blockedURI: event.blockedURI }, "*");
});
- document.getElementById("navigate").click();
+ const target = document.querySelector("iframe");
+ target.onload = () => {
+ target.onload = null;
+ const source = document.createElement("iframe");
+ source.src = "${sourceUrl.href}";
+ document.body.appendChild(source);
+ };
<\/script>`,
- },
- uniqueLocalhostHostname(`named-violation-source-${name}`)
+ { "Content-Security-Policy": `frame-src ${targetUrl.origin} ${sourceUrl.origin}` }
+ ),
+ uniqueLocalhostHostname(`named-violation-container-${name}`)
);
const reported = new Promise(resolve => {
@@ -63,24 +74,20 @@
resolve(event.data.blockedURI);
});
});
- const source = document.createElement("iframe");
- source.src = sourceUrl;
- document.body.appendChild(source);
+ const container = document.createElement("iframe");
+ container.src = containerUrl;
+ document.body.appendChild(container);
const blockedURI = await reported;
- source.remove();
+ container.remove();
return blockedURI;
};
- const afterRedirect = await blockedURIOfNavigation("redirect", `frame-src ${targetUrl.origin}`, redirectUrl.href);
+ const afterRedirect = await blockedURIOfNavigation("redirect", null, redirectUrl.href);
println(`After a redirect, the violation names the navigation's first URL: ${afterRedirect === redirectUrl.href}`);
const upgradedUrl = new URL(blockedUrl);
upgradedUrl.protocol = "https:";
- const upgraded = await blockedURIOfNavigation(
- "upgraded",
- `upgrade-insecure-requests; frame-src ${targetUrl.origin}`,
- blockedUrl.href
- );
+ const upgraded = await blockedURIOfNavigation("upgraded", "upgrade-insecure-requests", blockedUrl.href);
println(`Under upgrade-insecure-requests, the violation names the https URL: ${upgraded === upgradedUrl.href}`);
for (const message of messages) {
diff --git a/Tests/LibWebView/TestRendererViolationReports.cpp b/Tests/LibWebView/TestRendererViolationReports.cpp
index bad3ef92896..27f0e2361f2 100644
--- a/Tests/LibWebView/TestRendererViolationReports.cpp
+++ b/Tests/LibWebView/TestRendererViolationReports.cpp
@@ -240,8 +240,9 @@ TEST_CASE(renderer_violation_reports)
pages.set("/target"sv, { .headers = {}, .body = "<!DOCTYPE html>target" });
// A source frame beside its sibling, in a parent of its own origin that keeps the source's document alive once
- // the source navigates away. A violation of the source's policy posts to /violation-report.
- pages.set("/frames"sv, { .headers = {}, .body = R"(<!DOCTYPE html><body><script>
+ // the source navigates away. The parent's frame-src governs the sibling's navigations, and a violation of it posts
+ // to /violation-report.
+ pages.set("/frames"sv, { .headers = "Content-Security-Policy: frame-src http://source.test:* http://target.test:*; report-uri /violation-report\r\n", .body = R"(<!DOCTYPE html><body><script>
let sourceLoads = 0;
let siblingLoads = 0;
const sourceFrame = document.createElement("iframe");
@@ -347,6 +348,21 @@ TEST_CASE(renderer_violation_reports)
expect(spin_until_or_timeout([&] { return saw_title("reports handled"sv); }, 10'000), "the source handles every report it was sent"sv);
expect(!any_of(titles, [](auto const& title) { return title.starts_with("violation 4"sv); }), "neither a report for another navigation nor one from a page that is not the navigation's worker adds a violation"sv);
+ // The frame's container document is the source here, so a report of a violation of the container's policy, from
+ // the navigation's worker, reaches it.
+ auto report_to_container = [&](WebView::WebContentPage& page, WebView::CanonicalNavigable& navigable, Utf16String navigation_id, Web::ContentSecurityPolicy::RemoteViolationDirective directive) {
+ auto& stub = static_cast<WebContentClientStub&>(page.client());
+ stub.did_report_container_document_navigation_violation(page.id(), navigable.id(), move(navigation_id), 0, directive, false);
+ };
+ report_to_container(*worker, target, "not-the-navigation"_utf16, Web::ContentSecurityPolicy::RemoteViolationDirective::FrameSrc);
+ report_to_container(source_page, target, held_navigation->navigation_id, Web::ContentSecurityPolicy::RemoteViolationDirective::FrameSrc);
+ expect(worker->client().is_open() && source_page.client().is_open(), "a misdirected report for the container terminates no renderer"sv);
+ report_to_container(*worker, target, held_navigation->navigation_id, Web::ContentSecurityPolicy::RemoteViolationDirective::FrameSrc);
+ expect(spin_until_or_timeout([&] { return saw_title("violation 4: frame-src"sv); }, 10'000), "the container reports a report for its policy"sv);
+ source_view->run_javascript("setTimeout(() => setTimeout(() => (document.title = 'container reports handled')))"_string);
+ expect(spin_until_or_timeout([&] { return saw_title("container reports handled"sv); }, 10'000), "the container handles every report it was sent"sv);
+ expect(!any_of(titles, [](auto const& title) { return title.starts_with("violation 5"sv); }), "neither a report for the container about another navigation nor one from a page that is not the navigation's worker adds a violation"sv);
+
report(*worker, target, held_navigation->navigation_id, Web::ContentSecurityPolicy::RemoteViolationDirective::FormAction);
expect(!worker->client().is_open(), "the worker is terminated for a directive the navigation cannot violate"sv);
@@ -360,7 +376,7 @@ TEST_CASE(renderer_violation_reports)
expect(spin_until_or_timeout([&] { return frames_saw_title("source loaded 1"sv) && frames_saw_title("sibling loaded 1"sv); }, 10'000), "the source and its sibling load"sv);
frames_view->run_javascript("sourceFrame.contentWindow.navigateSibling('blocked.test', '/blocked')"_string);
- expect(spin_until_or_timeout([&] { return server.violation_reports() == 1; }, 10'000), "the source posts its violation's report"sv);
+ expect(spin_until_or_timeout([&] { return server.violation_reports() == 1; }, 10'000), "the sibling's container posts its violation's report"sv);
frames_view->run_javascript("sourceFrame.contentWindow.navigateSibling('target.test', '/held')"_string);
RefPtr<WebView::CanonicalNavigation> sibling_navigation;
@@ -392,5 +408,10 @@ TEST_CASE(renderer_violation_reports)
expect(!spin_until_or_timeout([&] { return server.violation_reports() > 1; }, 500), "a report for a replaced source is dropped"sv);
expect(sibling_worker->client().is_open(), "a report for a replaced source is no fault of its worker"sv);
+ // A container document's policy has no say over a form submission, so a report of one for the container is a lie.
+ auto& sibling_stub = static_cast<WebContentClientStub&>(sibling_worker->client());
+ sibling_stub.did_report_container_document_navigation_violation(sibling_worker->id(), sibling->id(), sibling_navigation->navigation_id, 0, Web::ContentSecurityPolicy::RemoteViolationDirective::FormAction, false);
+ expect(!sibling_worker->client().is_open(), "the worker is terminated for a container violation of form-action"sv);
+
outln("PASS: violation reports reach the source's page, and a report of a directive the navigation rules out terminates its renderer");
}