Skip to content

Truly independent web browser

LibWebView: Check a navigation another page routes to a navigable

Shannon Boothba80a7d98873
diff --git a/Libraries/LibWeb/HTML/RemoteNavigable.cpp b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
index ef1a45c6ee4..cb00d9f1b72 100644
--- a/Libraries/LibWeb/HTML/RemoteNavigable.cpp
+++ b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
@@ -220,7 +220,14 @@ WebIDL::ExceptionOr<void> RemoteNavigable::continue_navigation_in_active_documen
// window to continue these steps.
// NB: The active window lives in the process hosting the active document, so the task is a request to the UI
// process, which forwards it to that process.
- page().client().request_navigation_of_navigable(*this, create_prepared_navigation_descriptor(navigation));
+ auto fetch_client = navigation.source_snapshot_params->fetch_client;
+ if (!fetch_client)
+ return {};
+ auto& source_document = window_from_global_object(fetch_client->global_object())->associated_document();
+ auto source_navigable = source_document.navigable();
+ if (!source_navigable)
+ return {};
+ page().client().request_navigation_of_navigable(*this, *source_navigable, source_document, create_prepared_navigation_descriptor(navigation));
return {};
}
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index d5ba943e05e..8ea7f404c4b 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -597,7 +597,7 @@ public:
virtual void set_has_focus([[maybe_unused]] bool has_focus) { }
virtual bool has_active_devtools_client() const { return false; }
virtual void request_navigation_start(HTML::LocalNavigable&, NavigationTarget, URL::URL const& url, Utf16String navigation_id, Optional<HTML::NavigationStartRequest>);
- virtual void request_navigation_of_navigable(HTML::Navigable&, HTML::PreparedNavigationDescriptor) { VERIFY_NOT_REACHED(); }
+ virtual void request_navigation_of_navigable(HTML::Navigable&, HTML::Navigable&, DOM::Document const&, HTML::PreparedNavigationDescriptor) { VERIFY_NOT_REACHED(); }
virtual void request_post_message_to_remote_navigable(HTML::RemoteNavigable&, HTML::PostedMessageDescriptor) { VERIFY_NOT_REACHED(); }
virtual void request_close_of_remote_traversable(HTML::RemoteNavigable&, HTML::LocalNavigable const&) { VERIFY_NOT_REACHED(); }
virtual void request_focusing_steps_for_remote_navigable(HTML::RemoteNavigable&, HTML::FocusTrigger) { VERIFY_NOT_REACHED(); }
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 2315b6f0415..63f84e57712 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -304,6 +304,18 @@ void CanonicalNavigable::begin_navigation(Web::HTML::PreparedNavigationDescripto
worker->begin_navigation_unload_check(*this, navigation_id);
}
+void CanonicalNavigable::set_routed_navigation(Utf16String navigation_id, URL::Origin initiator_origin)
+{
+ m_routed_navigation = RoutedNavigation { move(navigation_id), move(initiator_origin) };
+}
+
+Optional<URL::Origin> CanonicalNavigable::take_routed_navigation_initiator_origin(Utf16String const& navigation_id)
+{
+ if (!m_routed_navigation.has_value() || m_routed_navigation->navigation_id != navigation_id)
+ return {};
+ return m_routed_navigation.release_value().initiator_origin;
+}
+
void CanonicalNavigable::begin_navigation_waiting_for_traversal()
{
if (!m_navigation_waiting_for_traversal.has_value() || ongoing_navigation_is_traversal())
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 0759f4b02de..5ac97f18f26 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -124,6 +124,11 @@ public:
Web::HTML::PreparedNavigationDescriptor prepare_navigation(URL::URL, Web::HTML::DocumentResource = {}, Web::Bindings::NavigationHistoryBehavior = Web::Bindings::NavigationHistoryBehavior::Auto);
void begin_navigation(Web::HTML::PreparedNavigationDescriptor);
bool has_navigation_waiting_for_traversal() const { return m_navigation_waiting_for_traversal.has_value(); }
+
+ // A navigation another page started for the navigable continues in the page hosting its document, with the
+ // initiator origin the UI process took from the page that started it.
+ void set_routed_navigation(Utf16String navigation_id, URL::Origin initiator_origin);
+ Optional<URL::Origin> take_routed_navigation_initiator_origin(Utf16String const& navigation_id);
void begin_navigation_waiting_for_traversal();
CanonicalBrowsingContext::BrowsingContextAndDocument obtain_a_browsing_context_to_use_for_a_navigation_response(NavigationLoader::ResponseDocument const&);
@@ -257,6 +262,11 @@ private:
RefPtr<CanonicalSessionHistoryEntry> m_active_session_history_entry;
Optional<CanonicalNavigation> m_ongoing_navigation;
Optional<Web::HTML::PreparedNavigationDescriptor> m_navigation_waiting_for_traversal;
+ struct RoutedNavigation {
+ Utf16String navigation_id;
+ URL::Origin initiator_origin;
+ };
+ Optional<RoutedNavigation> m_routed_navigation;
RefPtr<WebContentClient> process_to_host_for_site_isolation(CanonicalDocument const&, Optional<URL::Origin> const& initiator_origin) const;
ErrorOr<NonnullRefPtr<WebContentPage>> obtain_page_to_host_in(RefPtr<WebContentClient> process);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index da6c038b7d0..a4dceba2a97 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -662,16 +662,51 @@ bool WebContentPage::take_owed_reply(OwedReply owed)
static bool may_navigate_to_a_local_file(WebContentClient& requesting_client, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params);
-void WebContentPage::did_request_navigation_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation)
+void WebContentPage::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)
{
if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(client(), navigation.source_snapshot_params))
return;
+ auto target = traversable().find(navigable_id);
+ if (!target.has_value())
+ return;
+
+ // https://html.spec.whatwg.org/multipage/browsing-the-web.html#navigate
+ // NB: The page ran the steps up to 7 for a sourceDocument it hosts. The UI process runs those guarding navigable
+ // again, with the sourceDocument and sandboxing flags it holds. sourceDocument can be in another tab, in this
+ // process's page for it.
+ Optional<CanonicalNavigable&> source;
+ client().for_each_page([&](WebContentPage& page) {
+ auto navigable = page.traversable().find(source_navigable_id);
+ if (!navigable.has_value() || navigable->active_document().id() != source_document_id || navigable->active_document().host() != &page)
+ return IterationDecision::Continue;
+ source = *navigable;
+ return IterationDecision::Break;
+ });
+ if (!source.has_value())
+ return;
+ auto& source_document = source->active_document();
+
+ // 6. Otherwise:
+ // 2. If sourceDocument's node navigable is not allowed by sandboxing to navigate navigable given
+ // sourceSnapshotParams:
+ // 2. Return.
+ Web::InitiatorSourceSnapshot source_snapshot_params {
+ .sandboxing_flags = navigation.source_snapshot_params.sandboxing_flags | source_document.active_sandboxing_flag_set(),
+ .has_transient_activation = navigation.source_snapshot_params.has_transient_activation,
+ };
+ if (!source->allowed_by_sandboxing_to_navigate(*target, source_snapshot_params))
+ return;
+
+ // 3. Set initiatorOriginSnapshot to sourceDocument's origin.
+ navigation.initiator_origin_snapshot = source_document.origin();
+
// A document that was lost with the process that hosted it is navigated from step 8 on here: no process hosts it.
- if (auto target = traversable().top_level_traversable().find(navigable_id); target.has_value() && !target->active_document().host()) {
+ if (!target->active_document().host()) {
target->begin_navigation(move(navigation));
return;
}
+ target->set_routed_navigation(navigation.navigation_id, navigation.initiator_origin_snapshot);
// The request continues navigate at step 8 in the process hosting the target's document.
auto endpoint = endpoint_hosting_navigable_represented_by(navigable_id);
@@ -877,7 +912,7 @@ void WebContentPage::did_unhover_link()
view().on_link_unhover();
}
-static Optional<URL::Origin> initiator_origin_snapshot(URL::Origin const& given_origin, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params, WebContentClient* hosting_client = nullptr);
+static Optional<URL::Origin> initiator_origin_snapshot(URL::Origin const& given_origin, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params, WebContentClient& hosting_client);
// A page reaches local file content only by navigating there from local file content, or from the browser's UI: a
// process holding none could otherwise come to host a file: document, and with it read every file the user can.
@@ -905,7 +940,7 @@ static bool may_navigate_to_a_local_file(WebContentClient& requesting_client, We
static Optional<Web::HTML::PreparedNavigationDescriptor> navigation_from_page(WebContentClient& requesting_client, Web::HTML::PreparedNavigationDescriptor navigation)
{
// A page's own click or context menu names a document the page's process hosts, so only that process vouches for it.
- auto initiator_origin = initiator_origin_snapshot(navigation.initiator_origin_snapshot, navigation.source_snapshot_params, &requesting_client);
+ auto initiator_origin = initiator_origin_snapshot(navigation.initiator_origin_snapshot, navigation.source_snapshot_params, requesting_client);
if (!initiator_origin.has_value())
return {};
if (navigation.url.scheme() == "file"sv && !may_navigate_to_a_local_file(requesting_client, navigation.source_snapshot_params))
@@ -1879,29 +1914,18 @@ void WebContentPage::did_request_set_system_visibility_state(Web::HTML::Visibili
// NB: initiatorOriginSnapshot is sourceDocument's origin. The process names sourceDocument's relevant settings object as
// the fetch client, an environment that a process hosts, and the UI process takes the origin from it. Without a
// sourceDocument, the process gives a new opaque origin, which no document may hold yet.
-// The origin of the environment a navigation names as its fetch client, from the process hosting that environment. A
-// navigation a page starts in another process's navigable continues in that process (step 8 of navigate), so the
-// process asking isn't necessarily the one hosting the client; a caller that knows the host names it.
-static Optional<URL::Origin> initiator_origin_snapshot(URL::Origin const& given_origin, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params, WebContentClient* hosting_client)
+// The origin of the environment a navigation names as its fetch client, from the process asking, which hosts it.
+static Optional<URL::Origin> initiator_origin_snapshot(URL::Origin const& given_origin, Web::HTML::NavigationSourceSnapshot const& source_snapshot_params, WebContentClient& hosting_client)
{
if (!source_snapshot_params.fetch_client.has_value()) {
if (!given_origin.is_opaque() || CanonicalTraversable::is_origin_held_by_a_document(given_origin))
return {};
return given_origin;
}
- Optional<URL::Origin> origin;
- auto take_origin_from = [&](WebContentClient& client) {
- auto source_settings = client.hosted_environment(source_snapshot_params.fetch_client->id);
- if (!source_settings.has_value())
- return IterationDecision::Continue;
- origin = source_settings->origin();
- return IterationDecision::Break;
- };
- if (hosting_client)
- take_origin_from(*hosting_client);
- else
- WebContentClient::for_each_client(take_origin_from);
- return origin;
+ auto source_settings = hosting_client.hosted_environment(source_snapshot_params.fetch_client->id);
+ if (!source_settings.has_value())
+ return {};
+ return source_settings->origin();
}
void WebContentPage::did_request_navigation_start(Web::HTML::CrossProcessId navigable_id, Web::NavigationTarget target, URL::URL url, Utf16String navigation_id, Optional<Web::HTML::NavigationStartRequest> start_request)
@@ -1916,11 +1940,17 @@ void WebContentPage::did_request_navigation_start(Web::HTML::CrossProcessId navi
// Recheck it here so navigation admission and history traversal remain ordered by the UI process.
auto navigation_is_blocked_by_history_traversal = target_navigable
&& target_navigable->ongoing_navigation_is_traversal();
+ // The page hosting the navigable's document continues navigate at step 8, for a sourceDocument it hosts or for
+ // one another page hosts, which asked the UI process to route the navigation here.
Optional<URL::Origin> initiator_origin;
- if (start_request.has_value())
- initiator_origin = initiator_origin_snapshot(start_request->initiator_origin, start_request->source_snapshot_params);
+ if (start_request.has_value() && target_navigable) {
+ initiator_origin = initiator_origin_snapshot(start_request->initiator_origin, start_request->source_snapshot_params, client());
+ if (!initiator_origin.has_value())
+ initiator_origin = target_navigable->take_routed_navigation_initiator_origin(navigation_id);
+ }
if (!target_navigable
|| target_navigable->id() != navigable_id
+ || !traversable().hosts(*target_navigable, *this)
|| (start_request.has_value() && start_request->navigable_id != navigable_id)
|| (start_request.has_value() && !initiator_origin.has_value())
|| navigation_is_blocked_by_history_traversal) {
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 8ed91bd6a64..0fdcb202534 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -168,7 +168,7 @@ private:
void did_open_dialog(Web::PendingDialog, Utf16String const& message);
void maybe_record_history_visit_for_current_load(URL::URL const&, Optional<String> title, StringView reason);
- virtual void did_request_navigation_of_navigable(Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation) override;
+ 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 message) 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;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index ea664f01646..d14a92cf841 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -250,9 +250,9 @@ void PageClient::request_navigation_start(Web::HTML::LocalNavigable& navigable,
client().async_did_request_navigation_start(m_id, navigable.id(), target, url, move(navigation_id), move(start_request));
}
-void PageClient::request_navigation_of_navigable(Web::HTML::Navigable& navigable, Web::HTML::PreparedNavigationDescriptor navigation)
+void PageClient::request_navigation_of_navigable(Web::HTML::Navigable& navigable, Web::HTML::Navigable& source_navigable, Web::DOM::Document const& source_document, Web::HTML::PreparedNavigationDescriptor navigation)
{
- client().async_did_request_navigation_of_navigable(m_id, navigable.id(), move(navigation));
+ client().async_did_request_navigation_of_navigable(m_id, navigable.id(), source_navigable.id(), source_document.id(), move(navigation));
}
void PageClient::request_post_message_to_remote_navigable(Web::HTML::RemoteNavigable& navigable, Web::HTML::PostedMessageDescriptor message)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 2f1998ea505..c6773226409 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -187,7 +187,7 @@ private:
// ^PageClient
virtual bool is_connection_open() const override;
virtual void request_navigation_start(Web::HTML::LocalNavigable&, Web::NavigationTarget, URL::URL const& url, Utf16String navigation_id, Optional<Web::HTML::NavigationStartRequest>) override;
- virtual void request_navigation_of_navigable(Web::HTML::Navigable&, Web::HTML::PreparedNavigationDescriptor) override;
+ virtual void request_navigation_of_navigable(Web::HTML::Navigable&, Web::HTML::Navigable& source_navigable, Web::DOM::Document const& source_document, Web::HTML::PreparedNavigationDescriptor) override;
virtual void request_post_message_to_remote_navigable(Web::HTML::RemoteNavigable&, Web::HTML::PostedMessageDescriptor) override;
virtual void request_close_of_remote_traversable(Web::HTML::RemoteNavigable&, Web::HTML::LocalNavigable const& source) override;
virtual void request_focusing_steps_for_remote_navigable(Web::HTML::RemoteNavigable&, Web::HTML::FocusTrigger) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index 4bc15297ba2..d2394b7c8ff 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -85,7 +85,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_request_navigation_start(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::NavigationTarget target, URL::URL url, Utf16String navigation_id, Optional<Web::HTML::NavigationStartRequest> start_request) =|
did_complete_navigation_unload_check(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) =|
- did_request_navigation_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PreparedNavigationDescriptor navigation) =|
+ 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_request_close_of_traversable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) =|
did_request_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) =|