Content Security Policy Builder
Start from a strict, balanced or relaxed preset, then add your own directives. The tool checks every source and warns about risky choices.
Use the tool
Loading the tool…
About Content Security Policy Builder
Build a Content-Security-Policy header, a setting that tells a browser which sources a page may load scripts, images and other content from. Start from a preset: strict, balanced, relaxed or empty. Add your own directives, and an optional report address.
Worked example
Start from the balanced preset and add your own site's address for scripts. The tool outputs the header to add to your server.
Limits
A policy that is too strict can break a site, and one that is too loose gives little protection. Test the policy in report-only mode before you enforce it.
How to use Content Security Policy Builder
- Choose a starting preset.
- Add or change directives, one per line.
- Optionally set a report address and report-only mode.
- Copy the header in the format you need.
Good to know
- Try report-only mode first. The browser lists what would be blocked without blocking anything.
- 'unsafe-inline' lets injected scripts run. Prefer a nonce or a hash.
- frame-ancestors, base-uri and form-action do not fall back to default-src, so set them yourself.
- A meta tag cannot carry frame-ancestors, report-uri or sandbox. Use a real header for those.
Frequently asked questions
Will this break my site?
A strict policy can block scripts or styles you use. Start in report-only mode and fix what is reported.
How do I use a nonce?
Make a new random value for every page load, add 'nonce-VALUE' to script-src and put nonce="VALUE" on each script tag.
Does it test my live site?
No. It builds and checks the policy text only.