|
| 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://w3c.github.io/webappsec-csp/#directive-connect-src"> |
| 9 | +<link rel="help" href="https://github.com/whatwg/fetch/pull/1854"> |
| 10 | +<link rel="help" href="https://github.com/whatwg/html/pull/11620"> |
| 11 | +<link rel="compression-dictionary" href="/blockedRegistration?blockedFromElement"> |
| 12 | +<link rel="compression-dictionary" href="/allowedRegistration?allowedFromElement"> |
| 13 | +<script> |
| 14 | + let blocked = []; |
| 15 | + const observer = new ReportingObserver(reports => { |
| 16 | + for (const report of reports) { |
| 17 | + if (report.body.effectiveDirective === "connect-src") { |
| 18 | + const url = new URL(report.body.blockedURL); |
| 19 | + if (url.pathname.endsWith("Registration")) { |
| 20 | + blocked.push(url.search); |
| 21 | + } |
| 22 | + } |
| 23 | + } |
| 24 | + }, {types:["csp-violation"], buffered: true}); |
| 25 | + observer.observe(); |
| 26 | + |
| 27 | + // Link from HTTP headers are only loaded after page, so don't ever try to |
| 28 | + // run the test before. |
| 29 | + promise_setup(_ => new Promise(resolve => { |
| 30 | + if (document.readyState === 'complete') { |
| 31 | + resolve(); |
| 32 | + } else { |
| 33 | + addEventListener("load", resolve); |
| 34 | + } |
| 35 | + })); |
| 36 | + |
| 37 | + promise_test(async t => { |
| 38 | + let expectedBlocked = [ |
| 39 | + "?blockedFromElement", |
| 40 | + "?blockedFromHeader", |
| 41 | + ]; |
| 42 | + await t.step_wait(_ => blocked.length >= expectedBlocked.length, "<link> violating connect-src should trigger CSP violations", 3000); |
| 43 | + assert_array_equals(blocked.toSorted(), expectedBlocked); |
| 44 | + }, "link rel=compression-dictionary can be blocked via connect-src."); |
| 45 | +</script> |
0 commit comments