Skip to content

Commit

Permalink
HTML: COEP and ImageBitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk authored and natechapin committed Aug 23, 2019
1 parent 5a2b404 commit d7c4bb0
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
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

0 comments on commit d7c4bb0

Please sign in to comment.