webzod
account

Replace 'unsafe-inline' scripts with nonces or hashes on Cloudflare

headers.csp.script_unsafe_inline · effort: a project

Why it matters

With 'unsafe-inline' any script an attacker manages to inject into the page runs, which cancels most of what a CSP protects. Nonces or hashes let only the inline scripts you wrote run.

Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.

The fix

  1. A Transform Rule sends a fixed value, so it cannot carry a per-response nonce. Generate the nonce and header in your application, or in a Cloudflare Worker that rewrites the HTML.
  2. With the header produced at the origin, remove any Transform Rule that sets Content-Security-Policy (Set static would overwrite the origin's nonce), then roll out report-only first and enforce after.

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.