Summary
Whitelist script/style/connect sources — blocks inline script unless nonce/hash. Start report-only, tighten gradually. 'unsafe-inline' defeats most XSS protection. strict-dynamic for modern bundlers. Breakage symptoms: blocked analytics, fonts, WebSocket — check console CSP reports.
Code example
<meta http-equiv="Content-Security-Policy"
content="default-src 'self'; script-src 'self' 'nonce-R4nd0m'; connect-src 'self' https://api.example.com" />
Key points
- Whitelist script/style/connect sources — blocks inline script unless nonce/hash.
- Start report-only, tighten gradually.
'unsafe-inline'defeats most XSS protection.strict-dynamicfor modern bundlers.- Breakage symptoms: blocked analytics, fonts, WebSocket — check console CSP reports.