security
web_security
ai_generated
true
XSS despite CSP — Content-Security-Policy allows unsafe-inline
ID: security/csp-header-bypass-inline-script
88%Fix Rate
90%Confidence
4Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
CSP with unsafe-inline directive effectively disables script-src protection.
genericWorkarounds
-
93% success Use nonce-based CSP and add nonce attribute to all legitimate inline scripts
script-src 'nonce-abc123'
Sources: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
-
88% success Move all inline scripts to external files and use strict-dynamic
script-src 'strict-dynamic' 'nonce-xxx'
Sources: https://web.dev/articles/strict-csp
Dead Ends
Common approaches that don't work:
-
Add unsafe-inline to fix CSP errors from inline scripts
92% fail
unsafe-inline allows ANY inline script, completely defeating XSS protection
-
Use both nonce and unsafe-inline together for compatibility
70% fail
Browsers supporting nonces ignore unsafe-inline; those not supporting nonces allow all inline