Automatic update from web-platform-tests Add test to verify that link rel=compression-dictionary fetches can be blocked via connect-src -- wpt-commits: 49a6294ddb9565714cba508f21a436450725d85d wpt-pr: 61309
46 lines
1.7 KiB
HTML
46 lines
1.7 KiB
HTML
<!DOCTYPE html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="timeout" content="long"/>
|
|
<script src="./resources/compression-dictionary-util.sub.js"></script>
|
|
<script src="/resources/testharness.js"></script>
|
|
<script src="/resources/testharnessreport.js"></script>
|
|
<link rel="help" href="https://w3c.github.io/webappsec-csp/#directive-connect-src">
|
|
<link rel="help" href="https://github.com/whatwg/fetch/pull/1854">
|
|
<link rel="help" href="https://github.com/whatwg/html/pull/11620">
|
|
<link rel="compression-dictionary" href="/blockedRegistration?blockedFromElement">
|
|
<link rel="compression-dictionary" href="/allowedRegistration?allowedFromElement">
|
|
<script>
|
|
let blocked = [];
|
|
const observer = new ReportingObserver(reports => {
|
|
for (const report of reports) {
|
|
if (report.body.effectiveDirective === "connect-src") {
|
|
const url = new URL(report.body.blockedURL);
|
|
if (url.pathname.endsWith("Registration")) {
|
|
blocked.push(url.search);
|
|
}
|
|
}
|
|
}
|
|
}, {types:["csp-violation"], buffered: true});
|
|
observer.observe();
|
|
|
|
// Link from HTTP headers are only loaded after page, so don't ever try to
|
|
// run the test before.
|
|
promise_setup(_ => new Promise(resolve => {
|
|
if (document.readyState === 'complete') {
|
|
resolve();
|
|
} else {
|
|
addEventListener("load", resolve);
|
|
}
|
|
}));
|
|
|
|
promise_test(async t => {
|
|
let expectedBlocked = [
|
|
"?blockedFromElement",
|
|
"?blockedFromHeader",
|
|
];
|
|
await t.step_wait(_ => blocked.length >= expectedBlocked.length, "<link> violating connect-src should trigger CSP violations", 3000);
|
|
assert_array_equals(blocked.toSorted(), expectedBlocked);
|
|
}, "link rel=compression-dictionary can be blocked via connect-src.");
|
|
</script>
|