Truly independent web browser
LibWeb+LibWebView: Check sandboxing when navigating a parent frame
Shannon Booth947f71595611
diff --git a/Libraries/LibWeb/HTML/Navigable.cpp b/Libraries/LibWeb/HTML/Navigable.cppindex 57e4acca5f9..a4e3cb97abb 100644--- a/Libraries/LibWeb/HTML/Navigable.cpp+++ b/Libraries/LibWeb/HTML/Navigable.cpp@@ -262,13 +262,10 @@ bool Navigable::allowed_by_sandboxing_to_navigate(Navigable const& target, Sourcif (source.is_ancestor_of(target))return true;- // 3. If target is an ancestor of source, then:- if (target.is_ancestor_of(source)) {-- // 1. If target is not a top-level traversable, then return true.- if (!target.is_top_level_traversable())- return true;-+ // 3. If target is an ancestor of source:+ // AD-HOC: Only for a top-level target, which drops step 1, so that other ancestors reach step 5.+ // See https://github.com/whatwg/html/pull/13150+ if (target.is_top_level_traversable() && target.is_ancestor_of(source)) {// 2. If sourceSnapshotParams's has transient activation is true, and sourceSnapshotParams's sandboxing flags's// sandboxed top-level navigation with user activation browsing context flag is set, then return false.if (source_snapshot_params.has_transient_activation && has_flag(source_snapshot_params.sandboxing_flags, SandboxingFlagSet::SandboxedTopLevelNavigationWithUserActivation))diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex 5879748dbea..5a6ff53a696 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -611,12 +611,10 @@ bool CanonicalNavigable::allowed_by_sandboxing_to_navigate(CanonicalNavigable coif (source.is_ancestor_of(target))return true;- // 3. If target is an ancestor of source, then:- if (target.is_ancestor_of(source)) {- // 1. If target is not a top-level traversable, then return true.- if (!target.is_top_level_traversable())- return true;-+ // 3. If target is an ancestor of source:+ // AD-HOC: Only for a top-level target, which drops step 1, so that other ancestors reach step 5.+ // See https://github.com/whatwg/html/pull/13150+ if (target.is_top_level_traversable() && target.is_ancestor_of(source)) {// 2. If sourceSnapshotParams's has transient activation is true, and sourceSnapshotParams's sandboxing flags's// sandboxed top-level navigation with user activation browsing context flag is set, then return false.if (source_snapshot_params.has_transient_activationdiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.txtnew file mode 100644index 00000000000..96ac5dc96ab--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Check that sandboxed iframe can not navigate their ancestors\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.txt b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.txtnew file mode 100644index 00000000000..dd7189a9aae--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Check that unsandboxed iframe can navigate their ancestors\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.htmlnew file mode 100644index 00000000000..5a408a9e2ed--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-1.html@@ -0,0 +1,12 @@+<!doctype html>+<meta charset="utf-8">+<title>Check that sandboxed iframe can not navigate their ancestors</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script>+ var t = async_test();+ onmessage = t.step_func_done(function(e) {+ assert_equals(e.data, "can not navigate", "Should have the right message");+ });+</script>+<iframe sandbox="allow-scripts" src="support/iframe-tried-to-be-navigated-by-its-child.html"></iframe>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.htmlnew file mode 100644index 00000000000..cf5d59f9790--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/iframe_sandbox_navigate_ancestor-2.html@@ -0,0 +1,12 @@+<!doctype html>+<meta charset="utf-8">+<title>Check that unsandboxed iframe can navigate their ancestors</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>+<script>+ var t = async_test();+ onmessage = t.step_func_done(function(e) {+ assert_equals(e.data, "can navigate", "Should have the right message");+ });+</script>+<iframe src="support/iframe-tried-to-be-navigated-by-its-child.html"></iframe>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.htmlnew file mode 100644index 00000000000..4b8930de42f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html@@ -0,0 +1,11 @@+<!DOCTYPE html>+<p>This is a frame that tries to navigate its parent.</p>+<script>+window.onload = function() {+ try {+ parent.location.href = "data:text/html,\u003c!DOCTYPE html\u003e\u003cp\u003eIf this message appears, then this frame has been navigated by its child.\u003c/p\u003e\u003cscript\u003eparent.postMessage('can navigate', '*');\u003c/script\u003e";+ } catch(e) {+ parent.parent.postMessage("can not navigate", "*");+ }+}+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-tried-to-be-navigated-by-its-child.html b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-tried-to-be-navigated-by-its-child.htmlnew file mode 100644index 00000000000..50edc878adb--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/semantics/embedded-content/the-iframe-element/support/iframe-tried-to-be-navigated-by-its-child.html@@ -0,0 +1,4 @@+<!DOCTYPE html>+<p>If this message appears, then this frame has not been navigated by its child.</p>+<iframe src="iframe-that-tries-to-navigate-parent-and-sends-result-to-grandparent.html">+</iframe>