Toolstia / Content Security Policy generator
Content Security Policy generator
A Content Security Policy tells the browser which scripts, styles, images and frames a page may load. Pick a starting point, fill in the sources for each directive and copy the finished header, meta tag, nginx line or Apache line.
- A meta tag ignores frame-ancestors and report-uri. Send the policy as an HTTP header to use them.
Test a new policy in report-only mode first, because a policy that is too strict can break scripts, styles or images on your site. Keywords such as self and none are quoted for you.
How it works
- Choose a starting preset or start from scratch.
- Edit the sources for each directive, such as self or https://cdn.example.com.
- Turn on report-only mode if you want to test first, then copy the header.
What it does
A policy limits where content can come from. If a script is injected into your page from an unlisted place, the browser refuses to run it, which reduces the damage of cross-site scripting.
Keywords are quoted for you
Words such as self, none and unsafe-inline must be written in single quotes in a policy. The tool adds the quotes, and also quotes nonce and hash values.
Report-only mode
The report-only header logs what would have been blocked without blocking it. It is the safe way to try a new policy on a live site.
Header or meta tag
The HTTP header is the full form. A meta tag works for most directives but ignores frame-ancestors and report-uri, and cannot be report-only.
Questions
Is my policy sent anywhere?
Everything happens in your browser, and nothing you enter is sent anywhere.
Why does the tool warn about unsafe-inline?
Allowing inline scripts removes most of the protection a policy gives against injected scripts. Nonces or hashes are a safer way to allow your own inline code.
Will this break my site?
It can, if the policy blocks something the page needs. Start in report-only mode and watch the browser console before you enforce it.