Truly independent web browser
<!doctype html>
<script src="../include.js"></script>
<script>
asyncTest(async done => {
const server = httpTestServer();
const payloadURL = await server.createEcho("GET", "/svg-parser-inserted-script.js", {
status: 200,
headers: { "Content-Type": "text/javascript" },
body: "globalThis.svgParserInsertedScriptExecuted = true;",
});
const scriptStartTag = "<scr" + "ipt";
const scriptEndTag = "</scr" + "ipt>";
const pageBody = `<!DOCTYPE html>
${scriptStartTag} nonce="fixed">globalThis.svgParserInsertedScriptExecuted = false;${scriptEndTag}
<svg xmlns="http://www.w3.org/2000/svg">${scriptStartTag} href="${payloadURL}">${scriptEndTag}</svg>
${scriptStartTag} nonce="fixed">parent.postMessage(svgParserInsertedScriptExecuted ? "executed" : "blocked", "*");${scriptEndTag}`;
const pageURL = await server.createEcho("GET", "/svg-parser-inserted-script.html", {
status: 200,
headers: {
"Content-Type": "text/html",
"Content-Security-Policy": "script-src 'nonce-fixed' 'strict-dynamic'",
},
body: pageBody,
});
window.addEventListener(
"message",
event => {
println(`${event.data === "blocked" ? "PASS" : "FAIL"}: parser-inserted SVG script ${event.data}`);
done();
},
{ once: true }
);
const frame = document.createElement("iframe");
frame.src = pageURL;
document.body.appendChild(frame);
});
</script>