Web & application

CSP

Content Security Policy

A response header that tells the browser which scripts, styles, frames and connections a page may load, limiting the impact of XSS.

CSP is delivered as the Content-Security-Policy header (Level 3 is the current W3C draft). Directives such as script-src, object-src, base-uri, frame-ancestors and connect-src restrict sources. Content-Security-Policy-Report-Only tests a policy without enforcing it, and violations are sent to a report-to endpoint.

Allow-list policies (script-src 'self' cdn.example.com) are routinely bypassed through JSONP endpoints and script gadgets on allowed hosts. Google's research showed most such policies gave no real protection, which led to strict CSP: nonces or hashes plus strict-dynamic.

CSP is defence in depth, not an XSS fix. Common weaknesses: 'unsafe-inline', missing object-src 'none' and base-uri 'none', nonces reused across responses, and policies stuck in report-only for years.

A strict policyhttp
Content-Security-Policy: script-src 'nonce-r4nd0mPerResponse' 'strict-dynamic';
  object-src 'none'; base-uri 'none'; frame-ancestors 'self'; report-to csp

Learn it properly

Also used in

Related terms