Truly independent web browser
LibWeb: Set a navigation request's traversable for user prompts
Luke Wilde10ed46292aa8
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex 3aa13a21544..41a2297bfe8 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -2543,6 +2543,7 @@ static void create_navigation_params_by_fetching(// referrer: entry's document state's request referrer// referrer policy: entry's document state's request referrer policy// policy container: sourceSnapshotParams's source policy container+ // traversable for user prompts: navigable's top-level traversableauto request = Fetch::Infrastructure::Request::create();request->set_url(entry.url);if (source_snapshot_params->fetch_client)@@ -2558,6 +2559,7 @@ static void create_navigation_params_by_fetching(request->set_referrer(document_state.request_referrer);request->set_referrer_policy(document_state.request_referrer_policy);request->set_policy_container(source_snapshot_params->source_policy_container);+ request->set_traversable_for_user_prompts(navigable->top_level_traversable()->id());request->set_text_directive_user_activation(source_snapshot_params->text_directive_user_activation);request->set_browsing_context_group_has_multiple_contexts(source_snapshot_params->browsing_context_group_has_multiple_contexts);active_document.set_text_directive_user_activation(false);diff --git a/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.txt b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.txtnew file mode 100644index 00000000000..dd2184b7e1b--- /dev/null+++ b/Tests/LibWeb/Text/expected/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.txt@@ -0,0 +1,4 @@+messages: none+WebContent#0+ iframe#0: remote WebContent#1+ iframe#1: remote WebContent#2diff --git a/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.html b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.htmlnew file mode 100644index 00000000000..c01763de5ce--- /dev/null+++ b/Tests/LibWeb/Text/input/SiteIsolation/iframe/isolated-iframe-navigation-to-a-401-has-a-tab-to-prompt-in.html@@ -0,0 +1,59 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script>+ // An isolated iframe navigates a sibling that another process hosts to a response asking for credentials. The+ // navigation's request has the sibling's tab to prompt in, so the response does not load as a document.+ promiseTest(async () => {+ const httpServer = httpTestServer();+ const runId = uniqueID();+ const targetHostname = uniqueLocalhostHostname("prompt-target");++ const echo = async (path, status, headers, body, hostname) => {+ const url = new URL(+ await httpServer.createEcho("GET", path, {+ status,+ headers: { "Content-Type": "text/html", ...headers },+ body,+ })+ );+ url.hostname = hostname;+ return url;+ };++ const targetFirstUrl = await echo(`/prompt-target-first-${runId}`, 200, {}, "<!DOCTYPE html>first", targetHostname);+ const unauthorizedUrl = await echo(+ `/prompt-unauthorized-${runId}`,+ 401,+ { "WWW-Authenticate": 'Basic realm="test"' },+ `<!DOCTYPE html><script>top.postMessage("the 401 response loaded as a document", "*");<\/script>`,+ targetHostname+ );+ const sourceUrl = await echo(+ `/prompt-source-${runId}`,+ 200,+ {},+ `<!DOCTYPE html><a id="link" target="target" href="${unauthorizedUrl.href}">link</a>+ <script>document.getElementById("link").click();<\/script>`,+ uniqueLocalhostHostname("prompt-source")+ );++ const target = document.createElement("iframe");+ target.name = "target";+ target.src = targetFirstUrl;+ document.body.appendChild(target);+ await new Promise(resolve => (target.onload = resolve));++ const messages = [];+ addEventListener("message", event => messages.push(event.data));+ const navigated = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));++ const source = document.createElement("iframe");+ source.src = sourceUrl;+ document.body.appendChild(source);+ await navigated;+ await timeout(0);++ println(`messages: ${messages.length ? messages.join(", ") : "none"}`);+ println(internals.dumpSiteIsolationProcessTree().trimEnd());+ });+</script>