GUIDE 11 OF 11 · WEBSITE HEALTH CHECK

Content-Security-Policy: unsafe-inline, nonces and hashes

A Content-Security-Policy is the strongest header against injected scripts, and it is the hardest one to get right. The checker passes a policy only when it restricts scripts: no 'unsafe-eval', no 'unsafe-inline' without a nonce or a hash, and no * as a script source. No policy, a report-only policy or a weak one is a warning. It never fails, and it carries 5 of the 120 points.

Updated 5 December 2026Explains 1 check of the scanner behind the free tool

AT A GLANCE

  • No `Content-Security-Policy` header: a warning. Only `Content-Security-Policy-Report-Only`: a warning, because it blocks nothing.
  • Weak: script-src (or default-src, when there is no script-src) allows 'unsafe-eval', or 'unsafe-inline' with no nonce or hash, or *, or the policy has neither directive. A warning that names what it found.
  • Fine for the checker: nonces, hashes, 'strict-dynamic', 'wasm-unsafe-eval' and 'self'.
  • This site's own policy gets the warning. The reason, and why it is a trade-off and not an oversight, is below.
The checks this guide explains, and the points each one carries
CheckGroupPoints
Content-Security-Policy sec-cspSecurity5

What the check looks at

How the Content-Security-Policy check decides
What the page sendsResult
No CSP header at allWarning: no Content-Security-Policy header
Only Content-Security-Policy-Report-OnlyWarning: it is only in report-only mode, so it blocks nothing yet
A policy whose script sources include 'unsafe-eval'Warning, naming 'unsafe-eval'
A policy that includes 'unsafe-inline' and no 'nonce-...' or 'sha...' valueWarning, naming 'unsafe-inline' without nonces or hashes
A policy that lets scripts load from *Warning, naming the wildcard
A policy with no script-src and no default-srcWarning: scripts are not restricted
A policy with none of the problems abovePass: a Content-Security-Policy is set and restricts scripts

The script rule looks at script-src and falls back to default-src only when there is no script-src. Each warning comes with advice for what it found, so a site that only has 'unsafe-inline' is not told to remove 'unsafe-eval'.

Why 'unsafe-inline' counts as weak

The point of a CSP is to stop a script that an attacker has managed to put into your page from running. If the policy allows every inline script, the attacker's script is an inline script too, and nothing stops it. A nonce is a random value that your server creates for each request and puts both in the header and on your own script tags. A hash is the fingerprint of a script's exact text. Either one lets your scripts run and keeps anyone else's out.

How to add a policy without breaking the site

  1. Start in report-only mode. Send the policy as Content-Security-Policy-Report-Only and watch the browser console on each page: it names everything the policy would have blocked.
  2. Begin with `default-src 'self'` and add only what the site really loads: a font host, an analytics script, an embedded video.
  3. Add the directives that cost nothing: object-src 'none', base-uri 'self' and frame-ancestors 'self'.
  4. When the console is clean, send the same policy as `Content-Security-Policy`. Until then the checker will say it blocks nothing yet.

The Next.js trade-off: nonces or static pages

Next.js's own guide to CSP says that using nonces means every page must be rendered dynamically, on each request. A static page is built once, before any request exists, so there is nowhere to put a fresh nonce. The same guide lists what that costs: static optimisation and incremental static regeneration are switched off, pages cannot be cached by a CDN without extra work, and every request is rendered by the server. It also documents the other route, a policy "without nonces", which uses 'unsafe-inline'.

This site sends a policy without nonces. Its pages are static and served from a CDN, and the inline scripts that Next.js and the site's theme switch write into the page need 'unsafe-inline' to run. This is the policy it sends on every page, shortened:

From this site's response headers
Content-Security-Policy: default-src 'self'; script-src 'self' 'unsafe-inline' 'wasm-unsafe-eval'; ... object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'

By the checker's rules that policy is weak, because script-src has 'unsafe-inline' and no nonce or hash. So when this site is run through its own checker, the Content-Security-Policy check gives a warning. That warning is real, and it is a known trade-off, not an oversight. The rest of the policy still does real work: it stops scripts from other sites, blocks plug-ins, fixes the base address, limits where forms can post and says who may frame the page. What it cannot stop is an injected inline script.

A warning you can choose to keep

A score is a list of priorities, not a verdict. A static site with no user-written content gives an attacker far fewer ways to inject a script, and the price of nonces is paid in every page's speed. A site that shows other people's content, or handles money or private data, is the case where that price is worth paying.

What the check cannot see

  • It reads the script rule only. A strong script-src with a weak style-src passes.
  • A scheme source such as `https:` in script-src passes, though it lets scripts load from any HTTPS site.
  • It does not test the policy in a browser. A policy that passes the check can still block something your site needs, which is why the console is the real test.

Questions people ask

Why does the checker flag 'unsafe-inline'?

Because a policy that allows every inline script cannot tell your scripts from an attacker's. Nonces and hashes let only your own inline scripts run. The checker flags 'unsafe-inline' only when the policy has no nonce or hash at all.

Should I send the policy as report-only first?

Yes. It logs what would be blocked and blocks nothing, so you can fix the policy on a live site without breaking it. The checker gives a warning for a report-only policy because it protects nothing yet, so move it to the enforced header when the reports are clean.

Is 'wasm-unsafe-eval' a problem?

Not for this checker: it only flags 'unsafe-eval'. 'wasm-unsafe-eval' allows WebAssembly to compile without allowing JavaScript eval, and sites that load WebAssembly code need it. This site uses it for its 3D model decoder.

Where the facts come from

See also on this site

FREE · ABOUT TEN SECONDS · NOTHING STORED

Check your own site

Paste a web address into the free website health check. It runs the 36 checks these guides explain, gives a score out of 100, and says what to fix first.

Open the free website health check