Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 26 additions & 60 deletions html/document-isolation-policy/agent-cluster.tentative.https.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,10 @@
<script>
"use strict";

const origin = get_host_info().HTTPS_ORIGIN;
const noCorpURL = get_host_info().HTTPS_REMOTE_ORIGIN + "/html/document-isolation-policy/resources/nothing-no-corp.js";
// The smallest valid WebAssembly module.
const emptyModuleBytes = new Uint8Array([0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00]);

function executorURL(policy, uuid) {
return origin + executor_path + policy + `&uuid=${uuid}`;
}

function createFrame(t, url) {
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
const loaded = new Promise(resolve => frame.onload = resolve);
frame.src = url;
document.body.append(frame);
return loaded.then(() => frame);
}

// Runs the body of an async function in the context identified by uuid and returns its result.
async function runInContext(uuid, body) {
const reply = token();
send(uuid, `
(async () => {
let result;
try {
result = await (async () => { ${body} })();
} catch (e) {
result = e.name;
}
send("${reply}", JSON.stringify(result));
})();
`);
return JSON.parse(await receive(reply));
}

promise_test(async t => {
const uuid = token();
const frame = await createFrame(t, executorURL(dip_require_corp, uuid));
Expand All @@ -59,11 +28,7 @@
const uuid = token();
await createFrame(t, executorURL(dip_require_corp, uuid));
const result = await runInContext(uuid, `
const child = document.createElement("iframe");
const loaded = new Promise(resolve => child.onload = resolve);
child.src = ${JSON.stringify(executorURL(dip_none, token()))};
document.body.append(child);
await loaded;
${appendFrameScript(executorURL(dip_none, token()))}
let access;
try {
access = typeof child.contentWindow.document;
Expand All @@ -79,11 +44,7 @@
const uuid = token();
await createFrame(t, executorURL(dip_require_corp, uuid));
const result = await runInContext(uuid, `
const child = document.createElement("iframe");
const loaded = new Promise(resolve => child.onload = resolve);
child.src = ${JSON.stringify(executorURL(dip_require_corp, token()))};
document.body.append(child);
await loaded;
${appendFrameScript(executorURL(dip_require_corp, token()))}
return { contentDocument: child.contentDocument === null ? "null" : "document", access: typeof child.contentWindow.document };
`);
assert_object_equals(result, { contentDocument: "document", access: "object" });
Expand Down Expand Up @@ -179,8 +140,13 @@
document.body.append(frame);
await loaded;
const reply = token();
// A cross-document navigation can end the document before send() completes, so the result is also stored for its successor.
await runInContext(uuid, `
navigation.onnavigate = event => send("${reply}", event.sourceElement ? "element" : "null");
navigation.onnavigate = event => {
const sourceElement = event.sourceElement ? "element" : "null";
sessionStorage.setItem("${reply}", sourceElement);
send("${reply}", sourceElement);
};
return "ready";
`);
return { url: frame.src, reply };
Expand All @@ -207,10 +173,20 @@
assert_equals(await receive(reply), "element");
}, "A navigate event in a same-origin frame without a policy exposes a link of a document without one as its sourceElement");

promise_test(async t => {
const name = token();
const { reply } = await createNamedFrameWithNavigateListener(t, name);
const uuid = token();
await createFrame(t, executorURL(dip_require_corp, uuid));
const destination = token();
await runInContext(uuid, clickLinkScript(name, executorURL(dip_none, destination)));
assert_equals(await runInContext(destination, `return sessionStorage.getItem("${reply}") ?? "no navigate event";`), "null");
}, "A cross-document navigate event in a same-origin frame without a policy does not expose a link of a document with one as its sourceElement");

promise_test(async t => {
const uuid = token();
// The body arrives two seconds after the headers, so the fragment navigation happens while the reload is waiting for it.
const frame = await createFrame(t, origin + executor_path + dip_require_corp + "|trickle(d2)" + `&uuid=${uuid}`);
const frame = await createFrame(t, executorURL(dip_require_corp + "|trickle(d2)", uuid));
const reloaded = new Promise(resolve => frame.onload = resolve);
await runInContext(uuid, `
location.reload();
Expand Down Expand Up @@ -249,26 +225,16 @@
// Opens a cross-origin isolated popup and returns its uuid.
function openCrossOriginIsolatedPopup(t) {
const uuid = token();
window.open(origin + executor_path + coopSameOrigin + coepRequireCorp + `&uuid=${uuid}`);
window.open(executorURL(coopSameOrigin + coepRequireCorp, uuid));
t.add_cleanup(() => send(uuid, "window.close();"));
return uuid;
}

function appendFrameScript(url) {
return `
const child = document.createElement("iframe");
const loaded = new Promise(resolve => child.onload = resolve);
child.src = ${JSON.stringify(url)};
document.body.append(child);
await loaded;
`;
}

promise_test(async t => {
const topUUID = openCrossOriginIsolatedPopup(t);
const childUUID = token();
const result = await runInContext(topUUID, `
${appendFrameScript(origin + executor_path + coepRequireCorp + dip_require_corp + `&uuid=${childUUID}`)}
${appendFrameScript(executorURL(coepRequireCorp + dip_require_corp, childUUID))}
window.child = child;
let access;
try {
Expand Down Expand Up @@ -298,11 +264,11 @@
const topUUID = openCrossOriginIsolatedPopup(t);
const frameUUID = token();
await runInContext(topUUID, `
${appendFrameScript(remoteOrigin + executor_path + coepRequireCorp + corp_cross_origin + dip_require_corp + `&uuid=${frameUUID}`)}
${appendFrameScript(executorURL(coepRequireCorp + corp_cross_origin + dip_require_corp, frameUUID, remoteOrigin))}
return "loaded";
`);
const accessChild = policy => `
${appendFrameScript(remoteOrigin + executor_path + coepRequireCorp + policy + `&uuid=${token()}`)}
${appendFrameScript(executorURL(coepRequireCorp + policy, token(), remoteOrigin))}
try {
return typeof child.contentWindow.document;
} catch (e) {
Expand All @@ -316,7 +282,7 @@
promise_test(async t => {
const uuid = token();
// The opener has no Cross-Origin-Opener-Policy, so the response switches the popup to another browsing context group.
window.open(origin + executor_path + coopSameOrigin + dip_require_corp + `&uuid=${uuid}`);
window.open(executorURL(coopSameOrigin + dip_require_corp, uuid));
t.add_cleanup(() => send(uuid, "window.close();"));
const result = await runInContext(uuid, `
let fetchResult;
Expand All @@ -326,8 +292,8 @@
} catch (e) {
fetchResult = "blocked";
}
return { originAgentCluster, fetchResult };
return { originAgentCluster, crossOriginIsolated, fetchResult };
`);
assert_object_equals(result, { originAgentCluster: true, fetchResult: "blocked" });
assert_object_equals(result, { originAgentCluster: true, crossOriginIsolated: true, fetchResult: "blocked" });
}, "A popup with a policy keeps it when its response switches browsing context groups");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!doctype html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Document-Isolation-Policy: crossOriginIsolated and SharedArrayBuffer in popups and frames</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<body>
<script>
"use strict";

function openPopup(t, url) {
const popup = window.open(url);
t.add_cleanup(() => popup.close());
}

const getIsolation = "return { crossOriginIsolated, SharedArrayBuffer: typeof SharedArrayBuffer };";
const isolated = { crossOriginIsolated: true, SharedArrayBuffer: "function" };
const notIsolated = { crossOriginIsolated: false, SharedArrayBuffer: "undefined" };

[
{ policy: dip_require_corp, label: "with isolate-and-require-corp", expected: isolated, result: "is cross-origin isolated and exposes SharedArrayBuffer" },
{ policy: "", label: "without a policy", expected: notIsolated, result: "is not cross-origin isolated and does not expose SharedArrayBuffer" },
].forEach(({ policy, label, expected, result }) => {
promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(policy, uuid));
assert_object_equals(await runInContext(uuid, getIsolation), expected);
}, `A popup ${label} ${result}`);

promise_test(async t => {
const uuid = token();
await createFrame(t, executorURL(policy, uuid));
assert_object_equals(await runInContext(uuid, getIsolation), expected);
}, `A same-origin frame ${label} in a document without a policy ${result}`);
});

promise_test(async t => {
const uuid = token();
await createFrame(t, executorURL(dip_require_corp, uuid, get_host_info().HTTPS_REMOTE_ORIGIN), "cross-origin-isolated");
assert_object_equals(await runInContext(uuid, getIsolation), isolated);
}, `A cross-origin frame with isolate-and-require-corp and allow="cross-origin-isolated" in a document without a policy is cross-origin isolated and exposes SharedArrayBuffer`);

promise_test(async t => {
const popupUUID = token();
openPopup(t, executorURL(dip_require_corp, popupUUID));
const frameUUID = token();
await runInContext(popupUUID, `
${appendFrameScript(executorURL("", frameUUID))}
return "loaded";
`);
assert_object_equals(await runInContext(frameUUID, getIsolation), notIsolated);
}, "A same-origin frame without a policy in a popup with isolate-and-require-corp is not cross-origin isolated and does not expose SharedArrayBuffer");

promise_test(async t => {
const popupUUID = token();
openPopup(t, executorURL("", popupUUID, get_host_info().HTTP_ORIGIN));
const frameUUID = token();
await runInContext(popupUUID, `
${appendFrameScript(executorURL(dip_require_corp, frameUUID))}
return "loaded";
`);
assert_object_equals(await runInContext(frameUUID, getIsolation), notIsolated);
}, "A frame with isolate-and-require-corp in a popup that is not a secure context is not cross-origin isolated and does not expose SharedArrayBuffer");

promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(dip_require_corp, uuid));
assert_object_equals(await runInContext(uuid, `
const popup = window.open();
try {
return { crossOriginIsolated: popup.crossOriginIsolated, SharedArrayBuffer: typeof popup.SharedArrayBuffer };
} finally {
popup.close();
}
`), isolated);
}, "An about:blank popup opened by a popup with isolate-and-require-corp is cross-origin isolated and exposes SharedArrayBuffer");

[
{ label: "A frame navigated to about:blank", navigate: `frame.src = "about:blank";` },
{ label: "A srcdoc frame", navigate: `frame.srcdoc = "srcdoc";` },
].forEach(({ label, navigate }) => {
promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(dip_require_corp, uuid));
assert_object_equals(await runInContext(uuid, `
const frame = document.createElement("iframe");
await new Promise(resolve => {
frame.onload = resolve;
document.body.append(frame);
});
const loaded = new Promise(resolve => frame.onload = resolve);
${navigate}
await loaded;
return { crossOriginIsolated: frame.contentWindow.crossOriginIsolated, SharedArrayBuffer: typeof frame.contentWindow.SharedArrayBuffer };
`), isolated);
}, `${label} in a popup with isolate-and-require-corp is cross-origin isolated and exposes SharedArrayBuffer`);
});

promise_test(async t => {
const frame = await createFrame(t, executorURL(dip_require_corp, token()));
const reply = new Promise(resolve => window.onmessage = ({ data }) => resolve(data));
frame.src = "data:text/html," + encodeURIComponent(`<script>parent.postMessage({ crossOriginIsolated, SharedArrayBuffer: typeof SharedArrayBuffer }, "*");<\/script>`);
assert_object_equals(await reply, notIsolated);
}, "A data: URL document that a document without a policy navigates a frame with isolate-and-require-corp to is not cross-origin isolated and does not expose SharedArrayBuffer");

promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(dip_require_corp, uuid));
const dataURL = "data:text/html," + encodeURIComponent(`<script>parent.postMessage({ crossOriginIsolated, SharedArrayBuffer: typeof SharedArrayBuffer }, "*");<\/script>`);
assert_object_equals(await runInContext(uuid, `
${appendFrameScript(executorURL("", token()), "cross-origin-isolated *")}
const reply = new Promise(resolve => window.onmessage = ({ data }) => resolve(data));
child.src = ${JSON.stringify(dataURL)};
return await reply;
`), isolated);
}, "A data: URL document that a document with isolate-and-require-corp navigates a frame without a policy to is cross-origin isolated and exposes SharedArrayBuffer");
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<meta charset="utf-8">
<meta name="timeout" content="long">
<title>Document-Isolation-Policy: navigations between documents with different policies</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/get-host-info.sub.js"></script>
<script src="/common/utils.js"></script>
<script src="/common/dispatcher/dispatcher.js"></script>
<script src="./resources/common.js"></script>
<body>
<script>
"use strict";

function openPopup(t, url) {
const popup = window.open(url);
t.add_cleanup(() => popup.close());
}

[
{ from: dip_none, to: dip_require_corp, description: "without a policy to one with" },
{ from: dip_require_corp, to: dip_none, description: "with a policy to one without" },
].forEach(({ from, to, description }) => {
promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(from, uuid));
const key = token();
const destination = token();
// The document goes away when the navigation commits, so any failure is stored for its successor.
await runInContext(uuid, `
const record = failure => sessionStorage.setItem("${key}", failure);
navigation.onnavigateerror = event => record("navigateerror " + event.error.name);
const { committed, finished } = navigation.navigate(${JSON.stringify(executorURL(to, destination))});
committed.catch(error => record("committed " + error.name));
finished.catch(error => record("finished " + error.name));
return "navigating";
`);
await runInContext(destination, `return "loaded";`);
// Give the first document's handlers time to store a failure.
await new Promise(resolve => t.step_timeout(resolve, 500));
assert_equals(await runInContext(destination, `return sessionStorage.getItem("${key}") ?? "none";`), "none");
}, `navigation.navigate() from a document ${description} does not abort the navigation`);
});

[204, 205].forEach(status => {
promise_test(async t => {
const uuid = token();
openPopup(t, executorURL(dip_require_corp, uuid));
await runInContext(uuid, `
window.failure = "none";
navigation.onnavigateerror = event => window.failure = "navigateerror " + event.error.name;
navigation.navigate("/common/blank.html?pipe=status(${status})");
return "navigating";
`);
// Give a cancelled navigation time to report its failure.
await new Promise(resolve => t.step_timeout(resolve, 500));
assert_equals(await runInContext(uuid, `return window.failure;`), "none");
}, `A navigation to a ${status} response from a document with a policy leaves the document alone`);
});
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

const url = `${HTTPS_REMOTE_ORIGIN}/html/document-isolation-policy/resources/nothing-no-corp.js`;
const reply = new Promise(resolve => window.onmessage = ({ data }) => resolve(data));
frame.contentWindow.postMessage(`fetch(${JSON.stringify(url)}, { mode: "no-cors" }).then(response => parent.postMessage(response.type, "*"), () => parent.postMessage("blocked", "*"));`, "*");
assert_equals(await reply, "opaque");
frame.contentWindow.postMessage(`fetch(${JSON.stringify(url)}, { mode: "no-cors" }).then(response => response.type, () => "blocked").then(fetchResult => parent.postMessage({ fetchResult, crossOriginIsolated, SharedArrayBuffer: typeof SharedArrayBuffer }, "*"));`, "*");
assert_object_equals(await reply, { fetchResult: "opaque", crossOriginIsolated: false, SharedArrayBuffer: "undefined" });
}, "DIP requires a secure context, which an HTTPS iframe in an HTTP page is not");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
const response = await fetch(get_host_info().HTTPS_REMOTE_ORIGIN+"/html/document-isolation-policy/resources/nothing-no-corp.js", {mode: "no-cors"});
assert_equals(response.type, "opaque");
}, "DIP requires a secure context");

test(() => {
assert_false(crossOriginIsolated, "crossOriginIsolated");
assert_equals(typeof SharedArrayBuffer, "undefined", "SharedArrayBuffer");
}, "A document with DIP that is not a secure context is not cross-origin isolated and does not expose SharedArrayBuffer");
</script>
Loading