# What does ''unsafe-inline' allows the execution of unsafe in-page scripts and event handlers' mean?

**Short answer:** 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

```text
'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

1. Generate a random nonce per response and add it to the header and to each `<script>` tag.
2. Add `'strict-dynamic'` so scripts loaded by trusted scripts are allowed.
3. Remove inline event handlers and use `addEventListener`.
4. Ship as `Content-Security-Policy-Report-Only` first, then enforce.

```http
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.

> **Scan box (use the site's ScanBox component):** Check whether your live app has this problem. Paste your URL for a free outside-in scan covering exposed keys, open database rules, CORS and security headers. [Scan my app free →](https://proofforge.live/#scan)

## 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.

## Sources

- [Google CSP Evaluator](https://csp-evaluator.withgoogle.com/)
- [MDN: CSP script-src](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src)

## Related

- [Fix: missing security headers](/fix/missing-security-headers)
- [Security headers checker](/tools/security-headers-checker)
- [Fix 'Refused to load the script' (CSP violation)](/errors/refused-to-load-script-csp)
- [All errors](/errors)
