Skip to content

Truly independent web browser

LibWeb+LibWebView: Check incumbent's sandboxing flags in window.close()

Shannon Booth4c41de1010a2
diff --git a/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp b/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
index ce9332fa401..9af02a0ea39 100644
--- a/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalTraversableNavigable.cpp
@@ -212,11 +212,8 @@ void LocalTraversableNavigable::reset_session_history_for_testing()
active_window()->navigation()->initialize_the_navigation_api_entries_for_reconstructed_session_history(entries_for_navigation_api, active_entry);
}
-// https://html.spec.whatwg.org/multipage/document-sequences.html#close-a-top-level-traversable
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-close
-// AD-HOC: Step 6 of window.close(), requested through the UI process by a document another process hosts, whose
-// navigable found itself familiar with this traversable there. source is the incumbent global object's navigable.
-void LocalTraversableNavigable::close_top_level_traversable_from_script(Navigable const& source)
+void LocalTraversableNavigable::close_top_level_traversable_from_script()
{
// 1. Let thisTraversable be this's navigable.
auto& this_traversable = *this;
@@ -229,16 +226,15 @@ void LocalTraversableNavigable::close_top_level_traversable_from_script(Navigabl
if (this_traversable.is_closing())
return;
- // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given thisTraversable's active document.
- auto source_snapshot_params = snapshot_source_snapshot_params(this_traversable.active_document());
+ // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given the incumbent global object's
+ // associated Document.
+ // NB: The requesting process snapshotted it.
// 6. If all the following are true:
// - thisTraversable is script-closable;
// - the incumbent global object's browsing context is familiar with browsingContext; and
// - the incumbent global object's navigable is allowed by sandboxing to navigate thisTraversable, given sourceSnapshotParams,
- if (!this_traversable.is_script_closable() || !source.allowed_by_sandboxing_to_navigate(this_traversable, source_snapshot_params))
- return;
-
+ // NB: The requesting process found these true, and the UI process checked again the ones it holds the state for.
// then:
// 1. Set thisTraversable's is closing to true.
this_traversable.set_closing(true);
diff --git a/Libraries/LibWeb/HTML/LocalTraversableNavigable.h b/Libraries/LibWeb/HTML/LocalTraversableNavigable.h
index 0fdd2ed73ec..780fa371fac 100644
--- a/Libraries/LibWeb/HTML/LocalTraversableNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalTraversableNavigable.h
@@ -54,7 +54,7 @@ public:
void request_close_preflight(GC::Ref<GC::Function<void(bool)>> callback);
GC::Ptr<CheckUnloadingCanceledState> active_beforeunload_check(Badge<CheckUnloadingCanceledState>) const { return m_active_beforeunload_check; }
void set_active_beforeunload_check(Badge<CheckUnloadingCanceledState>, GC::Ptr<CheckUnloadingCanceledState> check) { m_active_beforeunload_check = check; }
- void close_top_level_traversable_from_script(Navigable const& source);
+ void close_top_level_traversable_from_script();
void definitely_close_top_level_traversable(PromptToUnload = PromptToUnload::Yes);
void run_ui_traversable_close_unload_task();
void destroy_top_level_traversable();
diff --git a/Libraries/LibWeb/HTML/RemoteNavigable.cpp b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
index 084d1699488..88b417ca35e 100644
--- a/Libraries/LibWeb/HTML/RemoteNavigable.cpp
+++ b/Libraries/LibWeb/HTML/RemoteNavigable.cpp
@@ -194,6 +194,19 @@ ReplicatedContainerState RemoteNavigable::container_state() const
return m_replicated_state.container;
}
+// https://html.spec.whatwg.org/multipage/nav-history-apis.html#script-closable
+bool RemoteNavigable::is_script_closable() const
+{
+ // A navigable is script-closable if it is a top-level traversable, and any of the following are true:
+ // - its is created by web content is true; or
+ // - its session history entries's size is 1.
+ if (!is_top_level_traversable())
+ return false;
+
+ return m_replicated_state.top_level_is_created_by_web_content
+ || m_replicated_state.top_level_session_history_entry_count == 1;
+}
+
bool RemoteNavigable::has_session_history_entry_and_ready_for_navigation() const
{
return m_replicated_state.has_session_history_entry_and_ready_for_navigation;
diff --git a/Libraries/LibWeb/HTML/RemoteNavigable.h b/Libraries/LibWeb/HTML/RemoteNavigable.h
index e143e635409..2aae619110f 100644
--- a/Libraries/LibWeb/HTML/RemoteNavigable.h
+++ b/Libraries/LibWeb/HTML/RemoteNavigable.h
@@ -47,7 +47,9 @@ public:
void set_window_proxy(GC::Ref<WindowProxy> window_proxy) { m_window_proxy = window_proxy; }
// https://html.spec.whatwg.org/multipage/document-sequences.html#is-closing
- bool is_closing() const { return m_replicated_state.is_closing; }
+ bool is_closing() const { return m_closing || m_replicated_state.is_closing; }
+ void set_closing(bool value) { m_closing = value; }
+ bool is_script_closable() const;
// https://html.spec.whatwg.org/multipage/document-sequences.html#document-tree-child-navigable
Vector<GC::Root<Navigable>> document_tree_child_navigables();
@@ -99,6 +101,9 @@ private:
GC::Ptr<LocalNavigable> m_provisional_navigable;
+ // Set by window.close() here, before the process hosting the navigable replicates its own.
+ bool m_closing { false };
+
bool m_has_been_destroyed { false };
};
diff --git a/Libraries/LibWeb/HTML/RemoteWindow.cpp b/Libraries/LibWeb/HTML/RemoteWindow.cpp
index 2cb34584459..e2a1c03d3de 100644
--- a/Libraries/LibWeb/HTML/RemoteWindow.cpp
+++ b/Libraries/LibWeb/HTML/RemoteWindow.cpp
@@ -7,9 +7,11 @@
#include <LibGC/Heap.h>
#include <LibWeb/HTML/LocalNavigable.h>
#include <LibWeb/HTML/Location.h>
+#include <LibWeb/HTML/NavigationSourceSnapshot.h>
#include <LibWeb/HTML/RemoteNavigable.h>
#include <LibWeb/HTML/RemoteWindow.h>
#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/SourceSnapshotParams.h>
#include <LibWeb/HTML/WindowProxy.h>
#include <LibWeb/Page/Page.h>
#include <LibWebCommon/HTML/PostedMessageDescriptor.h>
@@ -164,20 +166,35 @@ void RemoteWindow::close()
// 4. Let browsingContext be thisTraversable's active browsing context.
// NB: Familiarity is checked on the navigables whose active browsing contexts these are.
- // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given thisTraversable's active document.
- // NB: That document is in the process hosting the traversable, which runs the steps needing it.
+ auto& incumbent_global_object = incumbent_window();
- auto incumbent_navigable = incumbent_window().navigable();
+ // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given the incumbent global object's
+ // associated Document.
+ auto source_snapshot_params = snapshot_source_snapshot_params(incumbent_global_object.associated_document());
- // 6. If all the following are true:
- // - thisTraversable is script-closable;
- // - the incumbent global object's browsing context is familiar with browsingContext; and
- // - the incumbent global object's navigable is allowed by sandboxing to navigate thisTraversable, given sourceSnapshotParams,
- // then set thisTraversable's is closing to true, and queue a task on the DOM manipulation task source to definitely close thisTraversable.
- // NB: Familiarity is checked here; the process hosting the traversable's document checks the rest and closes it.
- if (!incumbent_navigable || !incumbent_navigable->is_familiar_with(*traversable))
+ auto incumbent_navigable = incumbent_global_object.navigable();
+ if (!incumbent_navigable)
return;
- m_navigable->page().client().request_close_of_remote_traversable(*traversable, *incumbent_navigable);
+
+ // 6. If all the following are true:
+ if (
+ // thisTraversable is script-closable;
+ traversable->is_script_closable()
+
+ // the incumbent global object's browsing context is familiar with browsingContext; and
+ && incumbent_navigable->is_familiar_with(*traversable)
+
+ // the incumbent global object's navigable is allowed by sandboxing to navigate thisTraversable, given sourceSnapshotParams,
+ && incumbent_navigable->allowed_by_sandboxing_to_navigate(*traversable, source_snapshot_params))
+ // then:
+ {
+ // 1. Set thisTraversable's is closing to true.
+ traversable->set_closing(true);
+
+ // 2. Queue a task on the DOM manipulation task source to definitely close thisTraversable.
+ // NB: The process hosting thisTraversable queues it once the UI process has checked the request.
+ m_navigable->page().client().request_close_of_remote_traversable(*traversable, *incumbent_navigable, create_navigation_source_snapshot(source_snapshot_params));
+ }
}
// https://html.spec.whatwg.org/multipage/interaction.html#dom-window-focus
diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp
index 602f684a0fb..4871b25e0b1 100644
--- a/Libraries/LibWeb/HTML/Window.cpp
+++ b/Libraries/LibWeb/HTML/Window.cpp
@@ -1227,10 +1227,12 @@ void Window::close()
// 4. Let browsingContext be thisTraversable's active browsing context.
// NB: Familiarity is checked on the navigables whose active browsing contexts these are.
- // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given thisTraversable's active document.
- auto source_snapshot_params = snapshot_source_snapshot_params(traversable->active_document());
-
auto& incumbent_global_object = HTML::incumbent_window();
+
+ // 5. Let sourceSnapshotParams be the result of snapshotting source snapshot params given the incumbent global object's
+ // associated Document.
+ auto source_snapshot_params = snapshot_source_snapshot_params(incumbent_global_object.associated_document());
+
auto incumbent_navigable = incumbent_global_object.navigable();
if (!incumbent_navigable)
return;
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 97fac331f59..f989bb82952 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -654,7 +654,7 @@ public:
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::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_close_of_remote_traversable(HTML::RemoteNavigable&, HTML::LocalNavigable const&, HTML::NavigationSourceSnapshot) { VERIFY_NOT_REACHED(); }
virtual void request_focusing_steps_for_remote_navigable(HTML::RemoteNavigable&, HTML::FocusTrigger) { VERIFY_NOT_REACHED(); }
virtual void request_window_focus_of_remote_navigable(HTML::RemoteNavigable&) { VERIFY_NOT_REACHED(); }
virtual void request_set_opener_of_remote_navigable(HTML::RemoteNavigable&, HTML::Navigable const&) { VERIFY_NOT_REACHED(); }
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 4aa5614e142..6946a5379ce 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -1170,6 +1170,20 @@ bool CanonicalNavigable::has_session_history_entry_and_ready_for_navigation() co
return is_top_level_traversable() || top_level_traversable().session_history().get_session_history_entries(*this).has_value();
}
+// https://html.spec.whatwg.org/multipage/nav-history-apis.html#script-closable
+bool CanonicalNavigable::is_script_closable() const
+{
+ // A navigable is script-closable if it is a top-level traversable, and any of the following are true:
+ // - its is created by web content is true; or
+ // - its session history entries's size is 1.
+ if (!is_top_level_traversable())
+ return false;
+
+ auto const& traversable = top_level_traversable();
+ return traversable.is_created_by_web_content()
+ || traversable.session_history().size() == 1;
+}
+
void CanonicalNavigable::document_completely_finished_loading(CanonicalDocument& document)
{
document.set_completely_loaded();
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index a0cd70e51bd..b554422f909 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -192,6 +192,7 @@ public:
bool active_document_has_cross_site_ancestor() const;
// Whether the navigable's active session history entry is among its session history entries.
bool has_session_history_entry_and_ready_for_navigation() const;
+ bool is_script_closable() const;
void document_completely_finished_loading(CanonicalDocument&);
void update_container_state(Web::HTML::ReplicatedContainerState);
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index 963507aa314..d037ffaaef5 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -1785,7 +1785,7 @@ void WebContentPage::nonchanging_navigable_history_state_updated(Web::HTML::Cros
traversable().did_receive_nonchanging_navigable_history_state_updated(*this, operation_id, navigable_id);
}
-void WebContentPage::did_request_close_of_traversable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id)
+void WebContentPage::did_request_close_of_traversable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::NavigationSourceSnapshot source_snapshot)
{
// window.close() from a document another process hosts: the process hosting the traversable's document runs the
// rest of its steps.
@@ -1794,13 +1794,27 @@ void WebContentPage::did_request_close_of_traversable(Web::HTML::CrossProcessId
// The process closing it must host the navigable it closes from. The request comes through the page holding the
// traversable's tab, which is not the source's when the two are different tabs.
- if (!client().hosted_navigable(source_navigable_id).has_value())
+ auto source = client().hosted_navigable(source_navigable_id);
+ if (!source.has_value())
+ return;
+
+ // https://html.spec.whatwg.org/multipage/nav-history-apis.html#dom-window-close
+ // 6. If all the following are true:
+ // - thisTraversable is script-closable;
+ // - the incumbent global object's navigable is allowed by sandboxing to navigate thisTraversable, given sourceSnapshotParams,
+ // NB: The requesting process found these true. The UI process checks them again with the state it holds, including
+ // the sandboxing flags of the incumbent global object's associated Document.
+ Web::InitiatorSourceSnapshot source_snapshot_params {
+ .sandboxing_flags = source_snapshot.sandboxing_flags | source->active_document().active_sandboxing_flag_set(),
+ .has_transient_activation = source_snapshot.has_transient_activation,
+ };
+ if (!traversable().is_script_closable() || !source->allowed_by_sandboxing_to_navigate(traversable(), source_snapshot_params))
return;
auto endpoint = endpoint_hosting_navigable_represented_by(navigable_id);
if (!endpoint)
return;
- endpoint->async_close_traversable_from_script(navigable_id, source_navigable_id);
+ endpoint->async_close_traversable_from_script(navigable_id);
}
void WebContentPage::did_inspect_dom_tree(String dom_tree)
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index c89349ebe68..4e1b8da376b 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -284,7 +284,7 @@ private:
virtual void request_child_navigable_unload(Web::HTML::CrossProcessId navigable_id) override;
virtual void changing_navigable_continuation_applied(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::HostedNavigableState> activated_navigable_state, Optional<Web::HTML::SessionHistoryEntryPersistedState> previous_entry_persisted_state) override;
virtual void nonchanging_navigable_history_state_updated(Web::HTML::CrossProcessId operation_id, Web::HTML::CrossProcessId navigable_id) override;
- virtual void did_request_close_of_traversable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) override;
+ virtual void did_request_close_of_traversable(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id, Web::HTML::NavigationSourceSnapshot source_snapshot) override;
virtual void did_inspect_dom_tree(String dom_tree) override;
virtual void did_inspect_dom_node(DOMNodeProperties properties) override;
virtual void did_finish_editing_dom_node(Optional<Web::UniqueNodeID> node_id) override;
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index cdfadc59719..1d0415f0de9 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -301,17 +301,13 @@ void ConnectionFromClient::deliver_posted_message(Web::PageId page_id, Web::HTML
page->deliver_posted_message(navigable_id, move(message));
}
-void ConnectionFromClient::close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id)
+void ConnectionFromClient::close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id)
{
auto page = this->page(page_id);
if (!page.has_value())
return;
- // The source is in another page of this process when it is in another tab.
- auto source = Web::HTML::navigable_with_id_in_any_page(page->page(), source_navigable_id);
- if (!source)
- return;
if (auto* traversable = as_if<Web::HTML::LocalTraversableNavigable>(page->page().navigable_with_id(navigable_id).ptr()))
- traversable->close_top_level_traversable_from_script(*source);
+ traversable->close_top_level_traversable_from_script();
}
void ConnectionFromClient::run_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger)
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index 30ff90b2dc6..5c4ec5e1a17 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -127,7 +127,7 @@ private:
virtual void create_navigation_params(Web::PageId page_id, Web::HTML::NavigationPopulationRequest) override;
virtual void cancel_navigation_params_creation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) override;
virtual void deliver_posted_message(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor) override;
- virtual void close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) override;
+ virtual void close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void run_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger) override;
virtual void focus_window_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void set_opener_of_navigable(Web::PageId page_id, 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 341e736c44b..98be8b5b2de 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -267,9 +267,9 @@ void PageClient::request_post_message_to_remote_navigable(Web::HTML::RemoteNavig
client().async_did_post_message_to_navigable(m_id, navigable.id(), move(message));
}
-void PageClient::request_close_of_remote_traversable(Web::HTML::RemoteNavigable& navigable, Web::HTML::LocalNavigable const& source)
+void PageClient::request_close_of_remote_traversable(Web::HTML::RemoteNavigable& navigable, Web::HTML::LocalNavigable const& source, Web::HTML::NavigationSourceSnapshot source_snapshot_params)
{
- client().async_did_request_close_of_traversable(m_id, navigable.id(), source.id());
+ client().async_did_request_close_of_traversable(m_id, navigable.id(), source.id(), move(source_snapshot_params));
}
void PageClient::request_focusing_steps_for_remote_navigable(Web::HTML::RemoteNavigable& navigable, Web::HTML::FocusTrigger focus_trigger)
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index d2aaffa0093..64c5aea443a 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -190,7 +190,7 @@ private:
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::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_close_of_remote_traversable(Web::HTML::RemoteNavigable&, Web::HTML::LocalNavigable const& source, Web::HTML::NavigationSourceSnapshot) override;
virtual void request_focusing_steps_for_remote_navigable(Web::HTML::RemoteNavigable&, Web::HTML::FocusTrigger) override;
virtual void request_window_focus_of_remote_navigable(Web::HTML::RemoteNavigable&) override;
virtual void request_set_opener_of_remote_navigable(Web::HTML::RemoteNavigable&, Web::HTML::Navigable const& opener) override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index f84f45e3b9b..3a70b0a3a61 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -88,7 +88,7 @@ endpoint WebContentClient routed by Web::PageId page_id
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::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_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) =|
did_request_set_opener_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId opener_navigable_id) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index 8ab8f329c7d..ebe459af163 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -104,7 +104,7 @@ endpoint WebContentServer routed by Web::PageId page_id
create_navigation_params(Web::PageId page_id, Web::HTML::NavigationPopulationRequest request) =|
cancel_navigation_params_creation(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Utf16String navigation_id) =|
deliver_posted_message(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::PostedMessageDescriptor message) =|
- close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId source_navigable_id) =|
+ close_traversable_from_script(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
run_focusing_steps_for_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::FocusTrigger focus_trigger) =|
focus_window_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
set_opener_of_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId opener_navigable_id) =|
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.ini
index 3e32b063971..50b5b29a92e 100644
--- a/Tests/LibWeb/TestConfig.ini
+++ b/Tests/LibWeb/TestConfig.ini
@@ -35,6 +35,7 @@ Text/input/HTML/window-open-finds-a-popup-by-target-name.html
Text/input/HTML/window-open-noopener-popup-keeps-its-name.html
Text/input/SiteIsolation/iframe/window-open-finds-a-popups-remote-iframe-by-target-name.html
Text/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.html
+Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.html
; Hear from a same-origin opener policy page over a BroadcastChannel.
Text/input/SiteIsolation/popup-navigating-to-a-coop-page-leaves-its-opener.html
diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.txt b/Tests/LibWeb/Text/expected/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.txt
index fc25a3ef5d4..7257908d514 100644
--- a/Tests/LibWeb/Text/expected/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.txt
+++ b/Tests/LibWeb/Text/expected/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.txt
@@ -1,4 +1,5 @@
arrived
popup.closed before close(): false
+popup.closed once close() returns: true
unloading
popup.closed after close(): true
diff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.txt
new file mode 100644
index 00000000000..b74b59e7ff6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.txt
@@ -0,0 +1,8 @@
+Harness status: OK
+
+Found 3 tests
+
+3 Pass
+Pass Sandboxed iframe without allow-top-navigation cannot close top window
+Pass Sandboxed iframe with allow-top-navigation can close top window
+Pass Cross-origin sandboxed iframe without allow-top-navigation cannot close top window
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.html b/Tests/LibWeb/Text/input/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.html
index 37da24daae1..df1bfe7ee17 100644
--- a/Tests/LibWeb/Text/input/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.html
+++ b/Tests/LibWeb/Text/input/SiteIsolation/popup-in-another-process-is-closed-by-its-opener.html
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<script src="../include.js"></script>
<script>
- // A popup in another process than its opener is closed by it, and the opener sees it closed by the time the popup's
- // document is unloaded.
+ // A popup in another process than its opener is closed by it, and the opener sees it closed as soon as close()
+ // returns.
promiseTest(async () => {
const httpServer = httpTestServer();
const runId = crypto.randomUUID();
@@ -30,6 +30,7 @@
println(`popup.closed before close(): ${popup.closed}`);
const unloading = nextMessage();
popup.close();
+ println(`popup.closed once close() returns: ${popup.closed}`);
println(await unloading);
println(`popup.closed after close(): ${popup.closed}`);
});
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/resources/sandbox-top-close-iframe.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/resources/sandbox-top-close-iframe.html
new file mode 100644
index 00000000000..653bc1d3565
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/resources/sandbox-top-close-iframe.html
@@ -0,0 +1,5 @@
+<!doctype html>
+<script>
+try { window.top.close(); } catch(e) {}
+window.parent.opener.postMessage('done', '*');
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.html
new file mode 100644
index 00000000000..167bb35a68d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.html
@@ -0,0 +1,8 @@
+<!doctype html>
+<meta charset=utf-8>
+<title>Sandboxed iframe top window close</title>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="../../../../common/get-host-info.sub.js"></script>
+<div id=log></div>
+<script src="../../../../html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.js"></script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.js b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.js
new file mode 100644
index 00000000000..22b0a2a6658
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/sandbox-top-close.sub.window.js
@@ -0,0 +1,44 @@
+// META: title=Sandboxed iframe top window close
+// META: script=/common/get-host-info.sub.js
+
+'use strict';
+
+const IFRAME_PATH = '/html/semantics/embedded-content/the-iframe-element/resources/sandbox-top-close-iframe.html';
+
+function testWithSandboxAttr(sandbox, xorigin = false) {
+ return new Promise(resolve => {
+ const popup = window.open('about:blank');
+
+ window.addEventListener('message', function handler(e) {
+ if (e.data !== 'done') return;
+ window.removeEventListener('message', handler);
+ const closed = popup.closed;
+ if (!closed) popup.close();
+ resolve(closed);
+ });
+
+ const iframe = popup.document.createElement('iframe');
+ iframe.sandbox = sandbox;
+ if (xorigin) {
+ iframe.src = get_host_info().HTTP_REMOTE_ORIGIN + IFRAME_PATH;
+ } else {
+ iframe.src = IFRAME_PATH;
+ }
+ popup.document.body.appendChild(iframe);
+ });
+}
+
+promise_test(async () => {
+ const closed = await testWithSandboxAttr('allow-scripts');
+ assert_false(closed);
+}, 'Sandboxed iframe without allow-top-navigation cannot close top window');
+
+promise_test(async () => {
+ const closed = await testWithSandboxAttr('allow-scripts allow-top-navigation');
+ assert_true(closed);
+}, 'Sandboxed iframe with allow-top-navigation can close top window');
+
+promise_test(async () => {
+ const closed = await testWithSandboxAttr('allow-scripts', true);
+ assert_false(closed);
+}, 'Cross-origin sandboxed iframe without allow-top-navigation cannot close top window');