Key directives
- default-src — the default policy for all resource types.
- script-src / style-src — script and style sources; modern policies use nonces or hashes instead of domain lists.
- frame-ancestors — who may embed the page in an iframe (clickjacking protection).
- report-to / report-uri — reporting policy violations to a designated endpoint.
How to deploy safely
Start with Content-Security-Policy-Report-Only mode, which only reports violations without blocking, analyze the reports, and only then enforce the policy. Avoid 'unsafe-inline' and broad whitelists — the recommended direction is a strict, nonce-based CSP with 'strict-dynamic'.
Example
A starter policy in Report-Only mode — collects violations without blocking scripts in production.
Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'nonce-abc123' 'strict-dynamic'; style-src 'self' 'nonce-abc123'; report-uri /csp-report<script nonce="abc123" src="/app.js"></script>