What does ''unsafe-inline' allows the execution of unsafe in-page scripts and event handlers' mean?
Your CSP's script-src includes 'unsafe-inline', so any script an attacker injects into the page will run, and the policy no longer stops XSS. Replace it with a per-request nonce (or hashes) and 'strict-dynamic'. Move inline event handlers (onclick=) into JS files.
Last updated 2026-11-25 · Reviewed by ProofForge
The exact error
'unsafe-inline' allows the execution of unsafe in-page scripts and event handlers. (Google CSP Evaluator, severity: high)Why it happens
- A framework or snippet needed inline scripts, so
'unsafe-inline'was added to make warnings go away. - Inline
onclick=handlers or<script>blocks without a nonce.
How to fix it
- Generate a random nonce per response and add it to the header and to each
<script>tag. - Add
'strict-dynamic'so scripts loaded by trusted scripts are allowed. - Remove inline event handlers and use
addEventListener. - Ship as
Content-Security-Policy-Report-Onlyfirst, then enforce.
Content-Security-Policy: script-src 'nonce-{RANDOM}' 'strict-dynamic' https: 'unsafe-inline'; object-src 'none'; base-uri 'none'Check it's fixed
Paste the policy into CSP Evaluator: no high-severity findings. The page works, and an injected inline script is blocked.
Check your live app
A free, read-only public-surface scan. It cannot diagnose private sessions or every cause described above.
FAQ
Why does the example still contain 'unsafe-inline'?
Browsers that support nonces ignore 'unsafe-inline' when a nonce or hash is present. It's only a fallback for very old browsers.
Is style-src 'unsafe-inline' as bad?
Less severe than for scripts, but it still allows CSS injection. Prioritize script-src.
Does Next.js support nonces?
Yes, via middleware that sets the CSP header and passes the nonce to the app.