What it means
Your Content-Security-Policy allows 'unsafe-inline' for scripts (in script-src, or in
default-src without a script-src) and has no nonce, hash or 'strict-dynamic' that would make browsers
ignore it. Any inline script runs, including injected ones.
Why it matters
Cross-site scripting usually works by getting an inline <script> or an event handler such as
onclick into a page. With 'unsafe-inline', the CSP doesn't stop that, so most of its protection is gone.
How to fix it
- Move inline scripts into files where you can, and replace
onclickattributes with event listeners. - For scripts that must stay inline, generate a random nonce per response and add it to the policy and the
tag:
script-src 'self' 'nonce-r4nd0m'and<script nonce="r4nd0m">. - For fixed inline scripts, a hash works too:
'sha256-...'of the script's content. - Add
'strict-dynamic'so scripts loaded by trusted scripts also run. - Remove
'unsafe-inline'; browsers that understand nonces ignore it anyway.
Check it worked
Run the HTTP and security headers check again. The finding should be gone once the policy has no
'unsafe-inline' or pairs it with a nonce or hash.