Skip to content
websniffer.click

Content-Security-Policy

Response header, security

Defines which sources of scripts, styles, images and frames the browser may load for this page.

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m' 'strict-dynamic'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'

A CSP is the most effective defence against cross-site scripting: even if an attacker injects a script tag, the browser refuses to run it unless the policy allows its source.

Policies that allow 'unsafe-inline' for scripts lose most of that protection. The modern approach is a nonce or hash per inline script combined with 'strict-dynamic'.

Roll out a new policy with Content-Security-Policy-Report-Only first, watch the violation reports, then switch to enforcement.

Check it on a live site

The security header check grades this header together with the others that protect visitors.

Specification: W3C CSP Level 3