Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script>
promiseTest(async () => {
const server = httpTestServer();
const hostname = uniqueLocalhostHostname("namespaced-script-crossorigin");
const setupURL = new URL(
await server.createEcho("GET", "/namespaced-script-setup", {
status: 200,
headers: {
"Content-Type": "text/html",
"Set-Cookie": "SID=secret; Path=/",
},
body: `<script>top.postMessage("ready", "*");<\/script>`,
})
);
setupURL.hostname = hostname;
const scriptURL = new URL(
await server.createEcho("GET", "/namespaced-script.js", {
status: 200,
headers: {
"Access-Control-Allow-Origin": "null",
"Access-Control-Allow-Credentials": "true",
"Content-Type": "text/javascript",
},
body: "",
})
);
scriptURL.hostname = hostname;
const ready = new Promise(resolve => addEventListener("message", resolve, { once: true }));
const setup = document.createElement("iframe");
setup.src = setupURL;
document.body.appendChild(setup);
await ready;
setup.remove();
const script = document.createElement("script");
script.setAttributeNS(null, "crossorigin", "anonymous");
script.setAttributeNS("urn:test", "crossorigin", "use-credentials");
const loaded = new Promise((resolve, reject) => {
script.onload = resolve;
script.onerror = reject;
});
script.src = scriptURL;
document.body.appendChild(script);
await loaded;
const recordedHeadersURL = server.recordedRequestHeadersURL(scriptURL);
const headers = await (await fetch(recordedHeadersURL)).json();
println(headers.Cookie ? "LEAK" : "PASS");
});
</script>