How to build a Content-Security-Policy that actually protects you
Every free CSP generator on the web does the same basic thing: you pick directives and it formats a header string. The differences that matter show up after deployment — a policy that quietly allows 'unsafe-inline' and a wildcard together, a nonce you cannot rotate, a header that breaks the checkout page because it was never run in Report-Only first, or a meta tag that silently drops frame-ancestors. The pages that top the results for "content security policy generator" — StrateCode, BlockSurvey, ToolGrid, nrtechstudio, ismycodesafe, Xerobit, ByteTools and Toolypet — are solid builders, and a few do one advanced thing well: BlockSurvey pairs a builder with a checker, nrtechstudio computes real hashes, ismycodesafe ships framework presets. None of them combines the builder and the checker, a real Web Crypto hash generator, a nonce generator, six deployment formats including a Cloudflare Transform Rule, and a step-by-step rollout checklist in one page.
This tool does exactly that. When you build a policy here, your browser:
- Starts from a preset — Strict (default-deny with a nonce), Balanced (works for most sites), or Permissive (a legacy-compatible starting point you tighten afterwards).
- Lets you tune every directive — toggle the common sources per directive, add your own hosts, and set report-uri and report-to for violation reports.
- Warns about dangerous combinations — 'unsafe-inline' with a wildcard, 'strict-dynamic' without a nonce, a missing object-src, base-uri or frame-ancestors — before you deploy.
- Formats it for your stack — the plain header, the Report-Only header, a meta tag (with the directives a meta tag cannot carry left out), Nginx, Apache, or a Cloudflare Transform Rule.
- Checks what you already have — paste any existing policy into the Check tab and get a score out of 100, every finding ranked, and a plain-English breakdown of each directive.
What makes this builder different
The ranking pages for "csp generator" and "csp header generator" are mostly single-purpose builders from small tool sites, and the strongest ones each cover one advanced feature — a checker, a hash calculator, or framework presets — but not the others. This page is the only one we found that combines the builder and the validator, real SHA-256/384/512 hashing in the browser, nonce generation with an honest note that your server must rotate nonces per response, six output formats, and a deployment checklist, with no upload, no account and no limits, plus a live network-request counter so you can verify the privacy claim yourself. It runs entirely in your browser — there is no server to upload to. The directive names and source keywords follow the MDN Content-Security-Policy reference.
When is this the right tool?
Whenever you ship a website and want to stop cross-site scripting at the browser level: a new launch, a security audit, a securityheaders.com scan that came back red, or a penetration test that found an XSS hole. Start with the Balanced preset, add the hosts your site really loads, run it in Report-Only for a few days, then enforce it. For a WordPress or legacy site, start with Permissive and tighten one directive at a time.
Honest limitations
The nonce is a demo value
A nonce only works if your server generates a fresh one on every response and injects it into both the header and each script tag. This builder makes a random 128-bit value for testing — it cannot rotate nonces for a live site. If your pages are fully static, use hashes instead.
It cannot see your site
The builder knows the policy you type, not the resources your site actually loads. Only your server logs and violation reports can tell you which hosts are missing — which is why the checklist starts with Report-Only.
Meta tags cannot do everything
Browsers ignore frame-ancestors, report-uri and report-to in a meta tag, and a meta tag cannot protect the page before it is parsed. The HTTP header is always preferred; the Meta tag format here leaves the unsupported directives out and says so.
The score is a guide, not a verdict
The 0–100 score weights the classic misconfigurations (wildcards, unsafe keywords, missing hardening directives). A policy can score 100 and still break a site that loads an unlisted host, or score lower and be the right trade-off for a legacy app. Read the findings, don't just chase the number.
report-to needs a separate header
The report-to directive only names an endpoint group — the group itself is defined by a Reporting-Endpoints header on your server. This builder writes the directive; your server still has to define the endpoint.
Old browsers ignore new directives
Very old browsers ignore directives they do not recognise, and some ignore CSP entirely. A CSP is one layer of defence, not a replacement for escaping output and keeping dependencies patched.