Skip to content

Commit 038de3e

Browse files
[CSP]: Do not block same-document navigations.
A cross-origin initiated same-document navigation caused crash when blocked by CSP. Stop blocking it + WPT regression test. This is #9 Mac crasher on M95 stable. So expect M96 (beta) cherry-pick. That's probably not enough for cherry-pick M95 (stable). Bug: 1262203 Change-Id: Ie70f77bd9ec69ac0659321f2e8e626b2bd091126 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3247135 Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org> Reviewed-by: Antonio Sartori <antoniosartori@chromium.org> Cr-Commit-Position: refs/heads/main@{#935920}
1 parent e7cc1ae commit 038de3e

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// META: script=/common/get-host-info.sub.js
2+
// META: script=/common/utils.js
3+
// META: script=/common/dispatcher/dispatcher.js
4+
5+
// Regression test for https://crbug.com/1262203
6+
//
7+
// A cross-origin document initiates a same-document navigation. This navigation
8+
// is subject to CSP:frame-src 'none', but this doesn't apply, since it's a
9+
// same-document navigation. This test checks this doesn't lead to a crash.
10+
11+
promise_test(async test => {
12+
const child_token = token();
13+
const child = new RemoteContext(child_token);
14+
const iframe = document.createElement("iframe");
15+
iframe.src = get_host_info().REMOTE_ORIGIN +
16+
"/content-security-policy/frame-src/support/executor.html" +
17+
`?uuid=${child_token}`;
18+
document.body.appendChild(iframe);
19+
20+
// Install a promise waiting for a same-document navigation to happen in the
21+
// child.
22+
await child.execute_script(() => {
23+
window.sameDocumentNavigation = new Promise(resolve => {
24+
window.addEventListener("popstate", resolve);
25+
});
26+
});
27+
28+
// Append a new CSP, disallowing new iframe navigations.
29+
const meta = document.createElement("meta");
30+
meta.httpEquiv = "Content-Security-Policy";
31+
meta.content = "frame-src 'none'";
32+
document.head.appendChild(meta);
33+
34+
document.addEventListener(
35+
"securitypolicyviolation",
36+
test.unreached_func("same-document navigations aren't subject to CSP"));
37+
38+
// Create a same-document navigation, inititated cross-origin in the iframe.
39+
// It must not be blocked by the CSP above.
40+
iframe.src += "#foo";
41+
42+
// Make sure the navigation succeeded and was indeed a same-document one:
43+
await child.execute_script(() => sameDocumentNavigation);
44+
assert_equals(await child.execute_script(() => location.href), iframe.src);
45+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
TODO(arthursonzogni) Consider deduplicating all these helper files to
3+
/common/dispatcher/
4+
-->
5+
<script src="/common/dispatcher/dispatcher.js"></script>
6+
<script>
7+
const params = new URLSearchParams(window.location.search);
8+
const uuid = params.get("uuid");
9+
const executor = new Executor(uuid);
10+
executor.execute();
11+
</script>

0 commit comments

Comments
 (0)