Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML: COEP and ImageBitmap #18543

Merged
merged 2 commits into from
Aug 21, 2019
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
50 changes: 50 additions & 0 deletions 2dcontext/imagebitmap/no-coop-coep.https.window.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// META: script=/common/utils.js
// META: script=/common/get-host-info.sub.js

function taintedImageBitmap(t) {
return new Promise(resolve => {
const img = new Image();
img.src = `${get_host_info().HTTPS_REMOTE_ORIGIN}/images/blue.png`;
img.onload = t.step_func(() => {
resolve(createImageBitmap(img));
});
img.onerror = t.unreached_func();
});
}

async_test(t => {
const bc = new BroadcastChannel(token());
const popup = window.open(`resources/coop-coep-popup.html?channel=${bc.name}`);
const popupReady = new Promise(resolve => {
bc.onmessage = t.step_func(resolve);
});
const imageReady = taintedImageBitmap(t);
Promise.all([popupReady, imageReady]).then(t.step_func(([, bitmap]) => {
bc.onmessage = t.step_func_done(e => {
assert_equals(e.data, "Got failure as expected.");
});
bc.postMessage(bitmap);
}));
}, "BroadcastChannel'ing a tainted ImageBitmap to a COOP+COEP popup");

[
{
"type": "serialize/deserialize",
"message": (port, bitmap) => port.postMessage(bitmap)
},
{
"type": "transfer",
"message": (port, bitmap) => port.postMessage(bitmap, [bitmap])
}
].forEach(({ type, message }) => {
async_test(t => {
const sw = new SharedWorker("resources/coop-coep-worker.js");
const imageReady = taintedImageBitmap(t);
imageReady.then(t.step_func(bitmap => {
sw.port.onmessage = t.step_func_done(e => {
assert_equals(e.data, "Got failure as expected.");
});
message(sw.port, bitmap);
}));
}, `Messaging a tainted ImageBitMap via ${type} to a COEP shared worker`);
});
11 changes: 11 additions & 0 deletions 2dcontext/imagebitmap/resources/coop-coep-popup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
const channel = new URLSearchParams(location.search).get("channel");
const bc = new BroadcastChannel(channel);
bc.onmessageerror = e => {
bc.postMessage("Got failure as expected.");
}
bc.onmessage = e => {
bc.postMessage("Got message, expected failure.");
}
bc.postMessage("Initialize");
</script>
2 changes: 2 additions & 0 deletions 2dcontext/imagebitmap/resources/coop-coep-popup.html.headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
9 changes: 9 additions & 0 deletions 2dcontext/imagebitmap/resources/coop-coep-worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
onconnect = e => {
const port = e.source;
port.onmessageerror = e => {
port.postMessage("Got failure as expected.");
}
port.onmessage = e => {
port.postMessage("Got message, expected failure.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Cross-Origin-Embedder-Policy: require-corp