Truly independent web browser
LibWebView: Check a navigation response's adherence to embedder policy
Shannon Boothdae26671df4a
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex fe70be2a391..788f3f386d6 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -3009,9 +3009,11 @@ void LocalNavigable::queue_navigation_and_traversal_task_for_session_history_ent// 4. Otherwise, if any of the following are true:// - navigationParams is null;// - the result of should navigation response to navigation request of type in target be blocked by Content Security Policy? given navigationParams's request, navigationParams's response, navigationParams's policy container's CSP list, cspNavigationType, and navigable is "Blocked";- // - FIXME: navigationParams's reserved environment is non-null and the result of checking a navigation response's adherence to its embedder policy given navigationParams's response, navigable, and navigationParams's policy container's embedder policy is false; or+ // - navigationParams's reserved environment is non-null and the result of checking a navigation response's adherence to its embedder policy given navigationParams's response, navigable, and navigationParams's policy container's embedder policy is false; or// - the result of checking a navigation response's adherence to `X-Frame-Options` given navigationParams's response, navigable, navigationParams's policy container's CSP list, and navigationParams's origin is false,// then:+ // NB: The UI process checks the response's adherence to its embedder policy, as it holds navigable's container+ // document.else if (navigation_params.visit([](NullOrError) { return true; },[this, csp_navigation_type](GC::Ref<NavigationParams> navigation_params) {diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cppindex 78c0359b9ba..905899783ec 100644--- a/Libraries/LibWebView/CanonicalTraversable.cpp+++ b/Libraries/LibWebView/CanonicalTraversable.cpp@@ -1329,6 +1329,7 @@ void CanonicalTraversable::continue_history_navigation_population(HistoryOperatiauto navigable_id = changing_navigable.id;auto navigable = changing_navigable.navigable().make_weak_ptr();loader->obtain_the_response_policies(*navigable);+ loader->check_the_responses_adherence_to_its_embedder_policy(*navigable);auto host_or_error = navigable->obtain_page_to_populate_document(target_entry, *loader, *endpoint);// Obtaining the page can replace the tab's process, whose change callbacks can end the job, and with its operationdiff --git a/Libraries/LibWebView/NavigationLoader.cpp b/Libraries/LibWebView/NavigationLoader.cppindex 637fcdab153..74ed4b4a15d 100644--- a/Libraries/LibWebView/NavigationLoader.cpp+++ b/Libraries/LibWebView/NavigationLoader.cpp@@ -245,6 +245,66 @@ void NavigationLoader::obtain_the_response_policies(CanonicalNavigable const& nanavigation_params->opener_policy = response_coop;}+// https://html.spec.whatwg.org/multipage/browsers.html#check-a-navigation-response's-adherence-to-its-embedder-policy+// NB: response is only used for violation reports, which are not queued.+static bool check_a_navigation_responses_adherence_to_its_embedder_policy(CanonicalNavigable const& navigable, Web::HTML::EmbedderPolicy const& response_policy)+{+ // 1. If navigable is not a child navigable, then return true.+ auto const* container_document = navigable.container_document();+ if (!container_document)+ return true;++ // 2. Let parentPolicy be navigable's container document's policy container's embedder policy.+ auto const& parent_policy = container_document->embedder_policy();++ // FIXME: 3. If parentPolicy's report-only value is compatible with cross-origin isolation and responsePolicy's value+ // is not, then queue a cross-origin embedder policy inheritance violation with response, "navigation",+ // parentPolicy's report-only reporting endpoint, "reporting", and navigable's container document's+ // relevant settings object.++ // 4. If parentPolicy's value is not compatible with cross-origin isolation or responsePolicy's value is compatible+ // with cross-origin isolation, then return true.+ if (!Web::HTML::is_compatible_with_cross_origin_isolation(parent_policy.value) || Web::HTML::is_compatible_with_cross_origin_isolation(response_policy.value))+ return true;++ // FIXME: 5. Queue a cross-origin embedder policy inheritance violation with response, "navigation", parentPolicy's+ // reporting endpoint, "enforce", and navigable's container document's relevant settings object.++ // 6. Return false.+ return false;+}++// https://html.spec.whatwg.org/multipage/browsing-the-web.html#attempt-to-populate-the-history-entry's-document+// NB: The UI process checks the response's adherence to its embedder policy, as it holds navigable's container+// document.+void NavigationLoader::check_the_responses_adherence_to_its_embedder_policy(CanonicalNavigable const& navigable)+{+ auto* navigation_params = m_result->navigation_params.get_pointer<Web::HTML::NavigationParamsDescriptor>();+ if (!navigation_params)+ return;++ // 5. Queue a global task on the navigation and traversal task source, given navigable's active window, to run these+ // steps:+ // 4. Otherwise, if any of the following are true:+ // [...]+ // - navigationParams's reserved environment is non-null and the result of checking a navigation response's+ // adherence to its embedder policy given navigationParams's response, navigable, and navigationParams's+ // policy container's embedder policy is false; or+ // [...]+ // then:+ // 1. Set entry's document state's document to the result of creating a document for inline content that+ // doesn't have a DOM, given navigable, null, navTimingType, and userInvolvement. The inline content+ // should indicate to the user the sort of error that occurred.+ // NB: The UI process checks this before the page that hosts the document queues the task, which creates that+ // document for navigation params that are null.+ if (!navigation_params->reserved_environment.has_value()+ || check_a_navigation_responses_adherence_to_its_embedder_policy(navigable, navigation_params->policy_container.embedder_policy)) {+ return;+ }+ release_response_body();+ m_result->navigation_params = Web::HTML::NavigationParamsNullOrError { "Blocked by Cross-Origin-Embedder-Policy"_utf16 };+}+void NavigationLoader::acquire_response_body(Function<void(bool)> completion_steps){VERIFY(m_result.has_value());diff --git a/Libraries/LibWebView/NavigationLoader.h b/Libraries/LibWebView/NavigationLoader.hindex e7b391e5ca7..02a89fadfe9 100644--- a/Libraries/LibWebView/NavigationLoader.h+++ b/Libraries/LibWebView/NavigationLoader.h@@ -60,6 +60,7 @@ public:void did_finish_navigation_params_creation(Web::HTML::NavigationPopulationResult);void acquire_response_body(Function<void(bool)> completion_steps);void obtain_the_response_policies(CanonicalNavigable const&);+ void check_the_responses_adherence_to_its_embedder_policy(CanonicalNavigable const&);// Moves the response over to the RequestServer of the process that will host the document, if that is another one.void move_response_body_to(RequestServerInstance&, Function<void(bool)> completion_steps);bool response_body_matches(int request_server_client_id, u64 request_server_request_id) const;diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cppindex e6f0e8781a1..1e4a2d3cc61 100644--- a/Libraries/LibWebView/WebContentPage.cpp+++ b/Libraries/LibWebView/WebContentPage.cpp@@ -313,6 +313,7 @@ bool WebContentPage::continue_navigation_population_in_selected_process(Web::HTMreturn false;navigation->loader()->obtain_the_response_policies(*navigable);+ navigation->loader()->check_the_responses_adherence_to_its_embedder_policy(*navigable);NonnullRefPtr history_entry = *navigation->history_entry;auto host_or_error = navigable->obtain_page_to_populate_document(history_entry, *navigation->loader(), *this);