About the Content Security Policy Generator
Content Security Policy Generator helps you write a Content-Security-Policy without memorising its syntax. Start from a secure starter template or a blank custom policy, tick the directives you need — default-src, script-src, style-src, img-src, font-src, connect-src, media-src, frame-src, object-src, base-uri, form-action and frame-ancestors — and add sources such as 'self', 'none', https:, data:, blob:, specific HTTPS origins, and nonce or hash placeholders. upgrade-insecure-requests, the deprecated block-all-mixed-content and extra directives such as worker-src or report-uri are supported too.
Every change is checked: invalid directive names, malformed origins, keywords missing quotes, duplicates and conflicts like 'none' with other sources are errors, while risky choices — 'unsafe-inline', 'unsafe-eval', *, broad schemes and data: for scripts — are highlighted but never removed. The tool outputs an HTTP header (or a Report-Only header) and an HTML meta tag, and explains which directives a meta tag cannot enforce. It creates a policy draft only; it does not fetch, scan or test any website.
How to use
- Click Secure starter template or Custom (blank).
- Tick the directives you need and add sources by typing or using “Add”.
- Read the checks and fix any errors; review every warning.
- Turn on Report-Only mode to test a policy without blocking anything.
- Copy the header or meta tag, or download everything as a .txt file.
Key features
- Editor for 12 common directives plus upgrade-insecure-requests and block-all-mixed-content.
- Secure starter template, custom mode and Report-Only mode.
- Quick-add sources including nonce and hash placeholders.
- Validation of directive names, origins, keywords, duplicates and conflicts.
- Warnings for unsafe-inline, unsafe-eval, wildcards, broad schemes and data: in scripts.
- HTTP header and meta tag output, with Copy, .txt download and Reset.
Best practices
- Deploy in Report-Only mode first and watch for violations.
- Prefer nonces or hashes to 'unsafe-inline' for scripts.
- Set object-src 'none' and base-uri 'self' (or 'none').
- Use the HTTP header rather than a meta tag where possible.
- Generate a new random nonce for every response — never reuse a fixed value.
Benefits
- Fewer syntax mistakes in a security-critical header.
- Clear explanations of risky choices.
- Ready-to-paste header and meta tag.
- Private: nothing is sent anywhere.
Frequently asked questions
Does this tool check my website?
No. It only builds and checks the policy text you enter. It does not fetch, scan or test any website, and it cannot tell whether the policy suits your site.
Why can’t frame-ancestors go in a meta tag?
Browsers ignore frame-ancestors, report-uri and sandbox in meta-tag policies. The tool leaves them out of the meta tag and explains this; use the HTTP header for them.
What is Report-Only mode?
Content-Security-Policy-Report-Only makes the browser report violations without blocking anything, so you can test a policy safely. It cannot be set with a meta tag.
Why is 'unsafe-inline' flagged?
It allows inline scripts and event handlers, which is exactly what most cross-site scripting attacks use. Nonces or hashes let you allow specific inline code instead.
How do I use the nonce placeholder?
Your server must replace it with a new, unpredictable value on every response and add the same value as a nonce attribute on each allowed <script> or <style> tag.
Will the tool remove risky sources for me?
No. Risky entries are highlighted with an explanation, but the policy contains exactly what you entered, so you stay in control.