What is a Content Security Policy (CSP)?

A Content Security Policy is an HTTP header that tells browsers which sources of scripts, styles and other resources a page may load, limiting the damage of cross-site scripting.

Free · no signup · passive checks only · results in under a minute

A Content Security Policy (CSP) is an HTTP response header that lists which sources a page is allowed to load scripts, styles, images, frames and other resources from. If an attacker manages to inject a script into your page, the browser refuses to run it unless it matches the policy.

Example

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

Key ideas

  • 'unsafe-inline' allows any inline script and removes most of CSP's protection against cross-site scripting.
  • Nonces and hashes allow specific inline scripts without allowing all of them.
  • frame-ancestors controls who may embed your page in an iframe, replacing X-Frame-Options.
  • Report-only mode (Content-Security-Policy-Report-Only) lets you test a policy without breaking anything.