Skip to content

Commit 1a5b856

Browse files
committed
Add test to verify that link rel=compression-dictionary fetches can be blocked via connect-src
1 parent c3b6f53 commit 1a5b856

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!DOCTYPE html>
2+
<head>
3+
<meta charset="utf-8">
4+
<meta name="timeout" content="long"/>
5+
<script src="./resources/compression-dictionary-util.sub.js"></script>
6+
<script src="/resources/testharness.js"></script>
7+
<script src="/resources/testharnessreport.js"></script>
8+
<link rel="help" href="https://html.spec.whatwg.org/#processing-the-type-attribute">
9+
<link rel="help" href="https://github.com/whatwg/html/pull/11620">
10+
<link rel="help" href="https://github.com/whatwg/html/pull/11620">
11+
<script>
12+
let blocked = [];
13+
self.addEventListener("securitypolicyviolation", e => {
14+
if (e.effectiveDirective === "connect-src") {
15+
const url = new URL(e.blockedURI);
16+
if (url.pathname.endsWith("Registration")) {
17+
blocked.push(url.search);
18+
}
19+
}
20+
});
21+
</script>
22+
<link rel="compression-dictionary" href="/blockedRegistration?blockedFromElement">
23+
<link rel="compression-dictionary" href="/allowedRegistration?allowedFromElement">
24+
<script>
25+
promise_test(async t => {
26+
await new Promise(resolve => addEventListener("load", resolve));
27+
let expectedBlocked = [
28+
"?blockedFromElement",
29+
"?blockedFromHeader",
30+
];
31+
await t.step_wait(_ => blocked.length >= expectedBlocked.length, "<link> violating connect-src should trigger CSP violations", 3000);
32+
assert_array_equals(blocked.toSorted(), expectedBlocked);
33+
}, "link rel=compression-dictionary can be blocked via connect-src.");
34+
</script>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Content-Security-Policy: connect-src *:*/allowedRegistration
2+
Link: </blockedRegistration?blockedFromHeader> ; rel="compression-dictionary"
3+
Link: </allowedRegistration?allowedFromHeader> ; rel="compression-dictionary"

0 commit comments

Comments
 (0)