Pick directives, add sources, and get a Content-Security-Policy header. The part worth having is the review underneath it. A policy containing 'unsafe-inline' in script-src blocks almost nothing — inline execution is exactly what an XSS payload needs — and it is the commonest mistake in this area precisely because nothing breaks and no errors appear, so people assume they are covered. That gets flagged. So does the assumption that a strict default-src covers everything: frame-ancestors, base-uri and form-action do not fall back to it, and are simply unenforced if you leave them out. An unset base-uri lets an injected <base> tag redirect every relative URL on your page. Report-only is on by default, because shipping an untested policy in enforcing mode is how you take a site down.
| Directive | If you omit it |
|---|---|
| frame-ancestors | Anyone can frame your page — clickjacking |
| base-uri | An injected <base> can redirect every relative URL |
| form-action | Forms can be made to submit anywhere |
| script-src | Falls back to default-src — covered |
| img-src | Falls back to default-src — covered |
It tells the browser which sources of script, style, images and other content are allowed to load and run on your page. Anything not permitted is blocked, which turns most cross-site-scripting bugs from an exploit into a console error.
Because inline script execution is the mechanism of almost every XSS attack. Allowing it means an injected <script> tag runs exactly as it would with no policy at all. The site keeps working, nothing logs an error, and the header provides a false sense of protection. Use a nonce or a hash for the inline scripts you genuinely need.
No, and this catches people out. It is the fallback for the fetch directives — script-src, img-src and their relatives — but frame-ancestors, base-uri and form-action ignore it completely. Leave those out and they are not enforced, however strict your default-src is.
Yes. Content-Security-Policy-Report-Only applies the policy and reports violations without blocking anything, so you can find what your own site would break before it breaks for visitors. Switch to the enforcing header once the reports are quiet.
Mostly, but not entirely. frame-ancestors is ignored in a meta tag, so clickjacking protection only works as a real HTTP header. If you can only set a meta tag, add X-Frame-Options as well.
It lets a script you have already trusted, via nonce or hash, load further scripts, while ignoring host allowlists. It is the modern approach for applications that load code dynamically, and it makes long CDN allowlists unnecessary.
Building the header string is trivial; the value is in what the tool refuses to let you do quietly. A policy containing 'unsafe-inline' in script-src provides essentially no cross-site-scripting protection, because inline script execution is exactly what an XSS payload needs — and it is the most common misconfiguration by a wide margin, precisely because it produces no console errors and no visible breakage. Someone adds the header, sees the site working, and believes they are protected. That is flagged as high severity, as is 'unsafe-eval' and a bare wildcard. The same value in style-src is flagged too, but as medium, because injected CSS can leak data through attribute selectors and background URLs without being able to execute code. The other thing the tool tracks is which directives actually fall back to default-src, because three of the most important ones do not: frame-ancestors, base-uri and form-action are each ignored entirely if omitted, no matter how strict default-src is. People assume a tight default-src covers them, and it does not — an unset base-uri lets an injected <base> tag redirect every relative URL on the page. Missing ones are reported. The meta-tag output carries its own caveat, since frame-ancestors is ignored when a policy is delivered that way and only works as a real header. Report-only is the default, because deploying an untested policy in enforcing mode breaks sites.