Truly independent web browser
LibWeb+LibWebView: Let a sandboxed iframe navigate its noopener popup
Shannon Booth5f295b96cd45
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 0515c91ced2..058d0266b63 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -1889,13 +1889,15 @@ LocalNavigable::ChosenNavigable LocalNavigable::choose_a_navigable(Utf16View nam// 1. Set chosen to the result of creating a new top-level traversable given currentNavigable's active browsing context, targetName, and currentNavigable.// FIXME: "and currentNavigable", which is the openerNavigableForWebDriver parameter.chosen = create_new_traversable(active_browsing_context());-- // 2. If sandboxingFlagSet's sandboxed navigation browsing context flag is set,- // then set chosen's active browsing context's one permitted sandboxed navigator to currentNavigable's active browsing context.- if (has_flag(sandboxing_flag_set, SandboxingFlagSet::SandboxedNavigation))- as<LocalNavigable>(*chosen).active_browsing_context()->set_the_one_permitted_sandboxed_navigator(active_browsing_context().ptr());}+ // 8.2. If sandboxingFlagSet's sandboxed navigation browsing context flag is set,+ // then set chosen's active browsing context's one permitted sandboxed navigator to currentNavigable's active browsing context.+ // AD-HOC: For a noopener popup too, or a sandboxed document could not navigate the popup a target=_blank link+ // opens. See https://github.com/whatwg/html/issues/12297+ if (has_flag(sandboxing_flag_set, SandboxingFlagSet::SandboxedNavigation))+ as<LocalNavigable>(*chosen).active_browsing_context()->set_the_one_permitted_sandboxed_navigator(active_browsing_context().ptr());+// 9. If sandboxingFlagSet's sandbox propagates to auxiliary browsing contexts flag is set,// then all the flags that are set in sandboxingFlagSet must be set in chosen's active browsing context's popup sandboxing flag set.if (has_flag(sandboxing_flag_set, SandboxingFlagSet::SandboxPropagatesToAuxiliaryBrowsingContexts))diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cppindex f48ee0bbcb8..57b2bf42c55 100644--- a/Libraries/LibWebView/CanonicalNavigable.cpp+++ b/Libraries/LibWebView/CanonicalNavigable.cpp@@ -655,7 +655,8 @@ CanonicalNavigable::ChosenTopLevelTraversable CanonicalNavigable::choose_a_new_t// 2. If sandboxingFlagSet's sandboxed navigation browsing context flag is set, then set chosen's active browsing// context's one permitted sandboxed navigator to currentNavigable's active browsing context.- if (opener.has_value() && has_flag(sandboxing_flag_set, Web::HTML::SandboxingFlagSet::SandboxedNavigation))+ // AD-HOC: For a noopener popup too. See https://github.com/whatwg/html/issues/12297+ if (has_flag(sandboxing_flag_set, Web::HTML::SandboxingFlagSet::SandboxedNavigation))chosen.active_browsing_context().set_the_one_permitted_sandboxed_navigator(current_navigable.active_browsing_context());// 9. If sandboxingFlagSet's sandbox propagates to auxiliary browsing contexts flag is set, then all the flags that arediff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 01e42494e84..4725ebc830b 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -66,6 +66,7 @@ Text/input/wpt-import/html/semantics/scripting-1/the-script-element/execution-ti; Opens popups that must be same-origin with the page.Text/input/HTML/window-open-finds-a-popup-by-target-name.htmlText/input/HTML/window-open-noopener-popup-keeps-its-name.html+Text/input/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.htmlText/input/SiteIsolation/sandboxed-iframe-navigates-its-cross-site-popup.htmlText/input/SiteIsolation/iframe/window-open-finds-a-popups-remote-iframe-by-target-name.htmlText/input/SiteIsolation/iframe/isolated-iframe-finds-a-popup-of-its-top-level-by-target-name.htmldiff --git a/Tests/LibWeb/Text/expected/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.txt b/Tests/LibWeb/Text/expected/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.txtnew file mode 100644index 00000000000..4785c406650--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.txt@@ -0,0 +1,2 @@+same-site iframe: the popup loaded+cross-site iframe: the popup loadeddiff --git a/Tests/LibWeb/Text/input/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.html b/Tests/LibWeb/Text/input/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.htmlnew file mode 100644index 00000000000..5e6eeab0a8c--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/sandboxed-iframe-link-navigates-its-noopener-popup.html@@ -0,0 +1,65 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ iframe {+ display: block;+ width: 200px;+ height: 100px;+ border: 0;+ }+</style>+<script>+ // A target=_blank link opens a noopener popup. A sandboxed iframe is the one permitted sandboxed navigator of that+ // popup, so the link navigates it although the iframe's sandboxed navigation browsing context flag is set.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const runId = crypto.randomUUID();+ const channelName = `sandboxed-link-popup-${runId}`;+ const channel = new BroadcastChannel(channelName);+ const nextMessage = () => new Promise(resolve => channel.addEventListener("message", event => resolve(event.data), { once: true }));++ const popupUrl = await httpServer.createEcho("GET", `/sandboxed-link-popup-${runId}`, {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `<!DOCTYPE html><script>+ new BroadcastChannel(${JSON.stringify(channelName)}).postMessage("the popup loaded");+ window.close();+ <\/script>`,+ });+ const linkDocument = `<!DOCTYPE html><style>body { margin: 0; } a { display: block; width: 200px; height: 100px; }</style>+ <a target="_blank" href="${popupUrl}">link</a>`;++ const crossSiteUrl = new URL(+ await httpServer.createEcho("GET", `/sandboxed-link-iframe-${runId}`, {+ status: 200,+ headers: { "Content-Type": "text/html" },+ body: `${linkDocument}<script>parent.postMessage("ready", "*");<\/script>`,+ })+ );+ crossSiteUrl.hostname = uniqueLocalhostHostname("sandboxed-link-iframe");++ const clickLinkIn = async (label, setUp) => {+ const iframe = document.createElement("iframe");+ iframe.sandbox = "allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts";+ const loaded = setUp(iframe);+ document.body.appendChild(iframe);+ await loaded;++ const popupLoaded = nextMessage();+ const rect = iframe.getBoundingClientRect();+ internals.clickThroughUIProcess(rect.left + 30, rect.top + 20);+ println(`${label}: ${await popupLoaded}`);+ iframe.remove();+ };++ await clickLinkIn("same-site iframe", iframe => {+ iframe.srcdoc = linkDocument;+ return new Promise(resolve => iframe.addEventListener("load", resolve, { once: true }));+ });++ await clickLinkIn("cross-site iframe", iframe => {+ iframe.src = crossSiteUrl;+ return new Promise(resolve => addEventListener("message", resolve, { once: true }));+ });+ });+</script>