mirror of
https://github.com/marcoallegretti/WEFT_OS.git
synced 2026-11-22 08:13:59 +00:00
test(frame): make the worker and srcdoc confinement probes observable
Servo refuses worker scripts for file: pages, blob: ones included, so the worker probe now requires only that no worker fetch succeeds, and the worker is built from the page itself. The srcdoc frame reports to a listener installed before the frame exists. Band failures and requests that reached the servers are reported together, so a run without the policy shows every leak.
This commit is contained in:
parent
16a184ad9e
commit
687439a2a3
3 changed files with 38 additions and 21 deletions
|
|
@ -13,7 +13,8 @@ The page probes, and paints one band per probe:
|
|||
- an image from a local HTTP server fails to load;
|
||||
- a no-cors fetch from that server is rejected;
|
||||
- a WebSocket to a local server that completes the handshake fails;
|
||||
- a no-cors fetch from a worker is rejected;
|
||||
- a worker does not fetch from that server (Servo does not start workers
|
||||
for file: pages, which also keeps them from fetching);
|
||||
- an about:srcdoc frame has no navigator.servo, which could change engine
|
||||
preferences.
|
||||
|
||||
|
|
@ -137,7 +138,6 @@ def make_package(store, http_port, ws_port, other_dir):
|
|||
.replace("@WS@", f"ws://127.0.0.1:{ws_port}/")
|
||||
.replace("@OTHER_URL@", other.as_uri()))
|
||||
(package / "ui/index.html").write_text(page)
|
||||
shutil.copy(fixture / "worker.js", package / "ui/worker.js")
|
||||
(package / "ui/own.png").write_bytes(png())
|
||||
(package / "outside.png").write_bytes(png())
|
||||
other.write_bytes(png())
|
||||
|
|
@ -177,12 +177,16 @@ def run(args, desktop, store, other_dir):
|
|||
if all(c == GREEN for c in colours.values()) or time.monotonic() > deadline:
|
||||
break
|
||||
time.sleep(0.5)
|
||||
time.sleep(1) # let requests the page sent after the last band arrive
|
||||
problems = []
|
||||
failed = [name for name, c in colours.items() if c != GREEN]
|
||||
if failed:
|
||||
raise AssertionError(f"probes not as required: {failed} ({colours})")
|
||||
problems.append(f"probes not as required: {failed}")
|
||||
if Counting.requests or connections:
|
||||
raise AssertionError(f"requests left the renderer: HTTP {Counting.requests}, "
|
||||
f"{len(connections)} WebSocket")
|
||||
problems.append(f"requests left the renderer: HTTP {sorted(Counting.requests)}, "
|
||||
f"{len(connections)} WebSocket")
|
||||
if problems:
|
||||
raise AssertionError("; ".join(problems))
|
||||
finally:
|
||||
stop.set()
|
||||
server.shutdown()
|
||||
|
|
|
|||
|
|
@ -11,6 +11,16 @@
|
|||
div { flex: 1; background: #808080; }
|
||||
iframe { position: absolute; width: 1px; height: 1px; border: 0; }
|
||||
</style>
|
||||
<script>
|
||||
// A srcdoc frame holds this page's content and must not reach the engine's
|
||||
// privileged navigator.servo interface; it reports what it sees.
|
||||
var srcdocReport = null;
|
||||
addEventListener('message', function (event) {
|
||||
if (typeof event.data === 'string' && event.data.indexOf('servo:') === 0) {
|
||||
srcdocReport = event.data;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="own-image"></div>
|
||||
|
|
@ -24,6 +34,14 @@
|
|||
<div id="worker-fetch"></div>
|
||||
<div id="srcdoc-internals"></div>
|
||||
<span>probe</span>
|
||||
<script type="text/plain" id="worker-source">
|
||||
// Reports whether a fetch to the URL it is sent leaves the worker.
|
||||
onmessage = function (event) {
|
||||
fetch(event.data, { mode: 'no-cors' }).then(
|
||||
function () { postMessage('fetched'); },
|
||||
function () { postMessage('refused'); });
|
||||
};
|
||||
</script>
|
||||
<iframe srcdoc="<img src='@HTTP@srcdoc.png'><script>parent.postMessage('servo:' + typeof navigator.servo, '*');</script>"></iframe>
|
||||
<script>
|
||||
// One band per probe: green when the outcome matches the policy, red when it
|
||||
|
|
@ -36,6 +54,7 @@
|
|||
var HTTP = '@HTTP@';
|
||||
var WS = '@WS@';
|
||||
var OTHER = '@OTHER_URL@';
|
||||
var WORKER = document.getElementById('worker-source').textContent;
|
||||
|
||||
function mark(id, ok) {
|
||||
document.getElementById(id).style.background = ok ? '#00c000' : '#e00000';
|
||||
|
|
@ -65,21 +84,21 @@ try {
|
|||
}
|
||||
|
||||
try {
|
||||
var worker = new Worker('worker.js');
|
||||
// A worker must never fetch past the policy. Servo currently refuses
|
||||
// worker scripts for file: pages, blob: ones included, so the worker does
|
||||
// not start; that also keeps it from fetching.
|
||||
var worker = new Worker(URL.createObjectURL(new Blob([WORKER], { type: 'text/javascript' })));
|
||||
worker.onmessage = function (event) { mark('worker-fetch', event.data === 'refused'); };
|
||||
worker.onerror = function () { mark('worker-fetch', false); };
|
||||
worker.onerror = function () { mark('worker-fetch', true); };
|
||||
worker.postMessage(HTTP + 'worker');
|
||||
} catch (e) {
|
||||
mark('worker-fetch', false);
|
||||
mark('worker-fetch', true);
|
||||
}
|
||||
|
||||
// A srcdoc frame holds this page's content and must not reach the engine's
|
||||
// privileged navigator.servo interface.
|
||||
addEventListener('message', function (event) {
|
||||
if (typeof event.data === 'string' && event.data.indexOf('servo:') === 0) {
|
||||
mark('srcdoc-internals', event.data === 'servo:undefined');
|
||||
}
|
||||
});
|
||||
(function srcdoc() {
|
||||
if (srcdocReport === null) { setTimeout(srcdoc, 50); return; }
|
||||
mark('srcdoc-internals', srcdocReport === 'servo:undefined');
|
||||
})();
|
||||
|
||||
try { navigator.sendBeacon(HTTP + 'beacon', 'probe'); } catch (e) {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +0,0 @@
|
|||
// Reports whether a fetch to the URL it is sent leaves the worker.
|
||||
onmessage = function (event) {
|
||||
fetch(event.data, { mode: 'no-cors' }).then(
|
||||
function () { postMessage('fetched'); },
|
||||
function () { postMessage('refused'); });
|
||||
};
|
||||
Loading…
Reference in a new issue