CSP Policy Builder
Build a Content-Security-Policy with presets for Google Analytics, AdSense and YouTube. Finds weak rules and gives header, .htaccess, Nginx and meta tag code.
Tool
About this tool
About CSP Policy Builder
A Content-Security-Policy tells the browser which scripts, styles, images and frames your page may load – the strongest protection against cross-site scripting (XSS). Writing one by hand is error-prone. Fill in each directive, tick presets for the services you use and the builder writes the policy, checks it for mistakes (missing quotes, wildcards, 'unsafe-inline', missing object-src, base-uri or frame-ancestors) and gives it to you as an HTTP header, an Apache .htaccess line, an Nginx line and a meta tag. You can also paste an existing policy to edit it, and start in Report-Only mode.
How it works
Example
How to use this tool
- Paste your current policy and press “Load policy”, or start from the safe defaults.
- Fill in the sources each directive needs and tick the presets you use.
- Read the checks, then copy the header – start with Report-Only.
Frequently asked questions
Will a CSP break my site?
It can, if you forget a source. Use Report-Only mode first, collect the reports for a week, then switch to enforce.
Why avoid 'unsafe-inline'?
It allows any inline script, which is exactly what XSS attacks inject. Use nonces or hashes for the inline scripts you really need.
Is my data uploaded?
No. Everything runs in your browser and stays on this device.
Does the CSP Policy Builder send my data to a server?
No. The CSP Policy Builder runs entirely in your browser using JavaScript, so tokens, code and data you paste stay on your device. You can even use it offline once the page has loaded.