
Content Security Policy (CSP) is the strongest browser-side defence against cross-site scripting. It tells the browser which sources of scripts, styles, images and frames are allowed, and blocks everything else.
A weak CSP, for example one that allows unsafe-inline or any HTTPS host, looks protective but blocks very little.
Most sites add CSP late and loosen it until nothing breaks. The result is a policy that allows inline scripts, eval or broad wildcards, which is exactly what an XSS payload needs.
frame-ancestors also protects against clickjacking.Content-Security-Policy-Report-Only and collect violation reports.unsafe-inline.unsafe-eval and broad wildcards such as https:.object-src 'none', base-uri 'self' and frame-ancestors.unsafe-inline allows inline scripts, which is exactly what most XSS payloads use. Replace it with nonces or hashes.
Start with Content-Security-Policy-Report-Only, review the violation reports, fix or allow legitimate sources, then enforce.
Try Vooki Pro free for 7 days
Check your Content Security Policy is actually doing its job. The trial unlocks every feature for 7 days, and scanning runs on your own machine.
Related: HTTP security headers: the essential list · HTTPS done right: HSTS and TLS configuration