Truly independent web browser
<!DOCTYPE html>
<script src="../../include.js"></script>
<script>
// An isolated iframe's form-action blocks a form it submits to a sibling that another process hosts. The process
// fetching for the sibling finds the violation, and the source iframe sees it as a securitypolicyviolation event.
promiseTest(async () => {
const httpServer = httpTestServer();
const runId = uniqueID();
const targetHostname = uniqueLocalhostHostname("form-action-target");
const echo = async (path, headers, body, hostname) => {
const url = new URL(
await httpServer.createEcho("GET", path, {
status: 200,
headers: { "Content-Type": "text/html", ...headers },
body,
})
);
url.hostname = hostname;
return url;
};
const targetFirstUrl = await echo(`/form-action-target-first-${runId}`, {}, "<!DOCTYPE html>first", targetHostname);
const targetSecondUrl = await echo(
`/form-action-target-second-${runId}`,
{},
`<!DOCTYPE html><script>top.postMessage("sibling navigated", "*");<\/script>`,
targetHostname
);
const blockedUrl = await echo(
`/form-action-blocked-${runId}`,
{},
`<!DOCTYPE html><script>top.postMessage("blocked form submission went through", "*");<\/script>`,
uniqueLocalhostHostname("form-action-blocked")
);
const sourceUrl = await echo(
`/form-action-source-${runId}`,
{ "Content-Security-Policy": `form-action ${targetSecondUrl.origin}` },
`<!DOCTYPE html>
<form id="blocked" target="target" method="GET" action="${blockedUrl.href}"></form>
<a id="allowed" target="target" href="${targetSecondUrl.href}">allowed</a>
<script>
document.addEventListener("securitypolicyviolation", event => {
top.postMessage([
"securitypolicyviolation in the source: " + event.effectiveDirective,
"disposition: " + event.disposition,
"blocked URL path matches: " + (new URL(event.blockedURI).pathname === "${blockedUrl.pathname}"),
"document URL matches: " + (event.documentURI === location.href),
].join(", "), "*");
});
addEventListener("message", () => document.getElementById("allowed").click());
document.getElementById("blocked").submit();
<\/script>`,
uniqueLocalhostHostname("form-action-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 = [];
let violationReported;
const reported = new Promise(resolve => (violationReported = resolve));
const navigated = new Promise(resolve => {
addEventListener("message", event => {
messages.push(event.data);
if (event.data.startsWith("securitypolicyviolation"))
violationReported();
if (event.data === "sibling navigated")
resolve();
});
});
const blockedNavigationLoaded = new Promise(resolve => target.addEventListener("load", resolve, { once: true }));
const source = document.createElement("iframe");
source.src = sourceUrl;
document.body.appendChild(source);
// The source navigates the sibling again only once its blocked navigation has finished.
await reported;
await blockedNavigationLoaded;
source.contentWindow.postMessage("navigate the sibling", "*");
await navigated;
for (const message of messages)
println(message);
println(internals.dumpSiteIsolationProcessTree().trimEnd());
});
</script>