DELAPARRA
Index
Color
NL
Category: HTTP headers

Content-Security-Policy

Explained by Updated

What is Content-Security-Policy?

Content-Security-Policy: CSP — controls what resources (scripts, styles, images) the browser is allowed to load. Strongest XSS defence in depth. Content Security Policy, or CSP, is a response header that tells the browser which sources of scripts, styles, images and other resources a page may load. Anything not on the list is blocked.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about Content-Security-Policy

How is Content-Security-Policy used in practice?

It is a strong second line of defence against cross-site scripting. Even if an attacker manages to inject a <script> tag into your page, the browser refuses to run it when the policy does not allow it.

What should you keep in mind with Content-Security-Policy?

Start with a strict base, such as default-src 'self', and add only what the site needs. Inline scripts are the usual obstacle; nonces or hashes let you allow specific ones safely. Roll a new policy out with Content-Security-Policy-Report-Only first, so violations are reported without breaking the site. Third-party widgets and analytics tags are often what makes a policy grow.

What does an example of Content-Security-Policy look like?

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-abc123'

At a glance

CategoryHTTP headers
Explained by
Updated

More HTTP headers terms

All terms starting with C

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.