Skip to content

Truly independent web browser

LibWeb: Don't navigate from a document without a navigable

Andreas Kling8bf7bafbfbef
diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cpp
index bc25c55e054..77b828658e8 100644
--- a/Libraries/LibWeb/HTML/Navigable.cpp
+++ b/Libraries/LibWeb/HTML/Navigable.cpp
@@ -183,9 +183,15 @@ WebIDL::ExceptionOr<void> Navigable::navigate(NavigateParams params)
// 1. Assert: userInvolvement is not "browser UI".
VERIFY(params.user_involvement != UserNavigationInvolvement::BrowserUI);
+ // AD-HOC: sourceDocument can have no node navigable, e.g. a document without a browsing context that a form
+ // moved into after it planned a navigation. There is nothing to navigate from.
+ auto source_navigable = source_document->navigable();
+ if (!source_navigable)
+ return {};
+
// 2. If sourceDocument's node navigable is not allowed by sandboxing to navigate navigable given
// sourceSnapshotParams:
- if (!source_document->navigable()->allowed_by_sandboxing_to_navigate(*this, snapshots.source_snapshot_params)) {
+ if (!source_navigable->allowed_by_sandboxing_to_navigate(*this, snapshots.source_snapshot_params)) {
// 1. If exceptionsEnabled is true, then throw a "SecurityError" DOMException.
if (params.exceptions_enabled)
return WebIDL::SecurityError::create("Source document's node navigable is not allowed to navigate"_utf16);
diff --git a/Tests/LibWeb/Crash/HTML/form-moved-to-document-without-navigable-before-planned-navigation.html b/Tests/LibWeb/Crash/HTML/form-moved-to-document-without-navigable-before-planned-navigation.html
new file mode 100644
index 00000000000..cf9c4e354b8
--- /dev/null
+++ b/Tests/LibWeb/Crash/HTML/form-moved-to-document-without-navigable-before-planned-navigation.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html class="test-wait">
+<iframe name="target"></iframe>
+<form action="?submitted" target="target"></form>
+<script>
+ const form = document.querySelector("form");
+ form.submit();
+ document.implementation.createHTMLDocument().body.appendChild(form);
+ setTimeout(() => {
+ document.documentElement.classList.remove("test-wait");
+ }, 100);
+</script>