1. Home
  2. Glossary
  3. Content-Security-Policy
Security

Content-Security-Policy (CSP)

An HTTP response header that lists which sources a page may load scripts, styles, images and other resources from. A strict policy limits the damage of cross-site scripting (XSS) attacks.

Why it matters

A strict policy is a strong extra layer of defence against cross-site scripting, because the browser refuses scripts from sources you did not list. It takes care to roll out, so test before enforcing.

Example

Content-Security-Policy: default-src 'self'; img-src 'self' data:

Where you will see it

The free Security headers checker looks at this on a live page and explains what it finds in plain English: grade HSTS, CSP and the other protective headers, with copy-paste fixes for Nginx, Apache, Cloudflare and Netlify.

Related terms

  • Clickjacking protection: Protection against another site embedding yours in a hidden frame to trick visitors into clicking.
  • Mixed content: An HTTPS page that loads some resources, such as images, scripts or styles, over plain HTTP. Browsers may block these or show a warning.
  • HTTP header: A name and value pair sent along with a request or a response.

Go deeper

  • Security headers explained: What HSTS, Content-Security-Policy, X-Content-Type-Options, frame-ancestors, Referrer-Policy and Permissions-Policy do, with safe example values.

← All 66 glossary terms

↑ ↓ to moveEnter to openEsc to closeAll results