Question
How does one nonce stay correct and isolated per response?
The Worker creates one nonce, shares it with the HTMLRewriter handler and CSP header, and gates scripts inside <noscript>.
Same origin HTML, rewritten with one per-response nonce on every eligible
<script> and a matching Content-Security-Policy header.
Scripts inside <noscript> are not nonced.
How does one nonce stay correct and isolated per response?
The Worker creates one nonce, shares it with the HTMLRewriter handler and CSP header, and gates scripts inside <noscript>.
<noscript> are not given a nonce./gzip and /br are transformed with identity body policy and safe response headers.Test the baseline first, then the capability response. Each column shows the request, observed values, and the success criterion it exercises.
The origin should have no CSP and should retain its stale nonce.
The response should add the CSP and match one fresh nonce to every eligible script.
Request the direct origin. The visible page and response should have no CSP and should retain the stale origin nonce.
curl -sS -D /tmp/s1-before.headers -o /tmp/s1-before.html https://s1-origin.thecompany-lab.com/ grep -iE '^(HTTP|content-security-policy|content-type)' /tmp/s1-before.headers || true grep -o 'old-origin-nonce' /tmp/s1-before.html | wc -l
Request the capability Worker and compare the policy-bearing header with the nonce attributes in its document.
curl -sS -D /tmp/s1-after.headers -o /tmp/s1-after.html https://s1.thecompany-lab.com/ grep -iE '^(HTTP|content-security-policy|cache-control|x-rs-transform-encoding)' /tmp/s1-after.headers grep -o 'nonce="[^"]*"' /tmp/s1-after.html | sort | uniq -c
The same fresh nonce should appear on every eligible script, while the stale value should be gone.
grep -c 'old-origin-nonce' /tmp/s1-after.html # expect 0 grep -o 'UNPROTECTED ORIGIN' /tmp/s1-after.html || true grep -o 'PROTECTED CAPABILITY' /tmp/s1-after.html
The Worker should report identity transform policy for both fixtures. Cloudflare may add client transport compression after the Worker returns.
for p in gzip br; do curl -sS -D "/tmp/s1-$p.headers" -o "/tmp/s1-$p.html" "https://s1.thecompany-lab.com/$p" echo "--- /$p" grep -iE '^(HTTP|content-encoding|x-rs-transform-encoding|cache-control)' "/tmp/s1-$p.headers" done