Skip to content

Truly independent web browser

LibWebView: Reject a child frame reported with an existing id

Shannon Booth8da18dd9df70
diff --git a/Libraries/LibWebView/CanonicalTraversable.cpp b/Libraries/LibWebView/CanonicalTraversable.cpp
index 2689ca05fba..f1ee07b05d3 100644
--- a/Libraries/LibWebView/CanonicalTraversable.cpp
+++ b/Libraries/LibWebView/CanonicalTraversable.cpp
@@ -154,28 +154,6 @@ CanonicalNavigable& CanonicalTraversable::insert(NonnullRefPtr<WebContentPage> r
return navigable_ref;
}
-void CanonicalTraversable::rehost(CanonicalNavigable& navigable, NonnullRefPtr<WebContentPage> reporting_page, CanonicalDocument& container_document, Web::HTML::HostedNavigableState hosted_state)
-{
- // The displayed document's child navigables go with it.
- while (!navigable.children().is_empty())
- remove(*navigable.children().last());
- navigable.clear_ongoing_navigation();
- navigable.discard_pending_host();
-
- // The page hosting the displayed document elsewhere retires the navigable's node: the page hosting its container
- // displays a document standing in for it from now on.
- RefPtr<WebContentPage> host = navigable.has_remote_host() ? &navigable.remote_host() : nullptr;
- if (host && host->is_open()) {
- VERIFY(navigable.replicated_state().has_value());
- host->async_stop_hosting_navigable(navigable.id(), *navigable.replicated_state());
- }
- navigable.active_document().set_host(reporting_page);
- navigable.set_container_document({}, container_document);
- navigable.update_hosted_state(move(hosted_state));
- if (host)
- release_page_if_unused(host.release_nonnull());
-}
-
// INTEROP: Reloading rebuilds child frames from the new document instead of restoring their previous entries.
void CanonicalTraversable::adopt_nested_history_for_created_child(CanonicalNavigable const& parent, CanonicalDocument const& container_document, Web::HTML::CrossProcessId child_navigable_id)
{
diff --git a/Libraries/LibWebView/CanonicalTraversable.h b/Libraries/LibWebView/CanonicalTraversable.h
index bcfc8739cde..55bb8524c0d 100644
--- a/Libraries/LibWebView/CanonicalTraversable.h
+++ b/Libraries/LibWebView/CanonicalTraversable.h
@@ -93,7 +93,6 @@ public:
void did_receive_nonchanging_navigable_history_state_updated(WebContentPage& source_page, Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id);
CanonicalNavigable& insert(NonnullRefPtr<WebContentPage> reporting_page, CanonicalNavigable& parent, CanonicalDocument& container_document, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState, NonnullRefPtr<CanonicalSessionHistoryEntry> active_session_history_entry, NonnullRefPtr<CanonicalDocument>);
- void rehost(CanonicalNavigable&, NonnullRefPtr<WebContentPage> reporting_page, CanonicalDocument& container_document, Web::HTML::HostedNavigableState);
void adopt_nested_history_for_created_child(CanonicalNavigable const& parent, CanonicalDocument const& container_document, Web::HTML::CrossProcessId child_navigable_id);
Optional<CanonicalNavigable&> find(Web::HTML::CrossProcessId navigable_id);
Optional<CanonicalNavigable const&> find(Web::HTML::CrossProcessId navigable_id) const;
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 55b076de5b9..7fd5a7e4fa4 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -751,26 +751,22 @@ void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_fra
{
auto& traversable = this->traversable();
- // A frame's parent frame is always created (and thus reported) before the frame itself, so if the parent is not in
- // the index, the parent is the traversable.
- auto parent = traversable.find(parent_frame_id);
- auto& parent_navigable = parent.has_value() ? *parent : static_cast<CanonicalNavigable&>(traversable);
+ // The parent can be gone by the time its frame is reported: its own container was removed meanwhile.
+ auto parent_navigable = traversable.find(parent_frame_id);
+ if (!parent_navigable.has_value())
+ return;
- auto container_document = parent_navigable.document_with_id(container_document_id);
+ auto container_document = parent_navigable->document_with_id(container_document_id);
if (!container_document || container_document->host() != this) {
client().did_misbehave("did_create_child_frame"sv, "frame created in a document the page does not hold"sv);
return;
}
- if (auto existing_navigable = traversable.find(frame_id); existing_navigable.has_value()) {
- if (existing_navigable->parent() != &parent_navigable) {
- client().did_misbehave("did_create_child_frame"sv, "frame created under another parent"sv);
- return;
- }
- traversable.rehost(*existing_navigable, *this, *container_document, move(hosted_state));
+ if (traversable.find(frame_id).has_value()) {
+ client().did_misbehave("did_create_child_frame"sv, "frame created with an existing navigable's id"sv);
return;
}
- traversable.adopt_nested_history_for_created_child(parent_navigable, *container_document, frame_id);
+ traversable.adopt_nested_history_for_created_child(*parent_navigable, *container_document, frame_id);
// https://html.spec.whatwg.org/multipage/document-sequences.html#create-a-new-child-navigable
// NB: The process creating the navigable reports the entry that initializing it, in step 8, created.
@@ -800,7 +796,7 @@ void WebContentPage::did_create_child_frame(Web::HTML::CrossProcessId parent_fra
// 7. Let navigable be a new navigable.
// 8. Initialize the navigable navigable given documentState and parentNavigable.
- traversable.insert(*this, parent_navigable, *container_document, frame_id, move(hosted_state), initial_entry.release_value(), move(document));
+ traversable.insert(*this, *parent_navigable, *container_document, frame_id, move(hosted_state), initial_entry.release_value(), move(document));
}
void WebContentPage::did_set_browser_zoom(double factor)