Skip to content
FixSecurityHeadersScan a site

Content-Security-Policy explained

Last updated · Reviewed by a CISSP-certified security practitioner

Content-Security-Policy: CSP is an allow-list for where your page may load scripts, styles, images, frames and connections from. It is the strongest defence against cross-site scripting. Recommended value: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'; upgrade-insecure-requests.

What risk does it prevent?

Without a CSP, any injected script (XSS, a compromised third‑party tag, a Magecart skimmer) runs with full access to your users' sessions and payment forms.

What is the safe recommended value?

Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data: https:; object-src 'none'; base-uri 'self'; frame-ancestors 'none'; form-action 'self'; upgrade-insecure-requests

What are the gotchas?

  • Deploy as Content-Security-Policy-Report-Only first and watch reports before enforcing.
  • 'unsafe-inline' and 'unsafe-eval' in script-src remove most of the XSS protection. Use nonces or hashes.
  • Analytics, chat widgets and payment iframes need their hosts added explicitly.
  • Only one CSP header should be sent; multiple policies are intersected, which often blocks more than expected.

Which compliance controls reference it?

  • PCI DSS 4.0 6.4.3
  • PCI DSS 4.0 11.6.1
  • OWASP ASVS V14.4.3
  • SOC 2 CC6.8
  • NIST 800-171 3.13.1

How do I add it on my stack?

Check your site now

Free scan, instant grade, exact fixes for your stack.

Other security headers