This free content security policy generator builds a CSP one directive at a time, adds the other HTTP security headers (HSTS, Permissions-Policy, X-Frame-Options and friends), and hands you ready-to-paste config for Nginx, Apache, Caddy, Traefik, IIS or WordPress. A second tab grades the headers a site already sends: paste them, and every finding comes with a plain-English reason.
I built it because a CSP is easy to get almost right. A comma instead of a space, self without quotes or a missing semicolon still looks fine, yet the browser quietly drops the part you wrote. This content security policy generator checks every change as you type and tells you what the browser will actually do with it.
What This Content Security Policy Generator Does
- 🧭 Presets to start from: a same-origin starter, Google’s nonce-based “strict CSP”, a compatible preset for themes that print inline scripts, and a lock-down policy for JSON APIs.
- 🧩 One field per directive: each field shows what it falls back to when empty, with quick-add buttons for
'self','none', a nonce placeholder,'strict-dynamic'and the risky keywords, which are marked in red. - 🔌 13 third-party services in one click: Google Analytics 4, Tag Manager, Google Fonts, YouTube, Vimeo, Google Maps, reCAPTCHA, Cloudflare Turnstile, hCaptcha, Stripe, Cloudflare Web Analytics, Plausible and Gravatar, with hosts taken from each vendor’s own documentation.
- 🔑 Hashes for inline code: paste an inline script or style and the content security policy generator returns its SHA-256, SHA-384 or SHA-512 source, calculated the way the browser calculates it.
- 🔒 The rest of the headers: HSTS with preload-list checks, X-Frame-Options that follows your
frame-ancestors,nosniff, Referrer-Policy, Permissions-Policy for 22 browser features, cross-origin isolation headers and violation reporting. - 📦 10 output formats: raw headers, Nginx, Apache, Caddy, Traefik labels or file provider, Netlify and Cloudflare Pages
_headers, an HTML<meta>tag, WordPress/PHP and IISweb.config, each escaped for its own syntax. - 📊 An analyzer with a score: paste
curl -Ioutput, DevTools headers, a bare policy or a<meta>tag and get a 100-point score, a letter grade and a finding for every header.
How to Use the Content Security Policy Generator
- Pick a preset. Starter suits most static and self-hosted sites; choose Strict CSP if your app can put a fresh nonce on every script tag.
- Tick the services your pages load, then adjust the directives. The Checks panel updates as you type and flags anything unsafe or invalid.
- Set HSTS, framing, Referrer-Policy and Permissions-Policy in the sections below the CSP.
- Choose your server under Format; the content security policy generator writes the matching config, ready to copy or download.
- Roll the policy out as Report-Only first, fix what the browser console reports, then switch to enforce. To confirm, run
curl -sI https://your-site.exampleand paste the output into the Analyzer tab.
Why It Reads Pasted Headers Instead of Fetching a URL
The analyzer in this content security policy generator never asks for a URL, on purpose. A web page can only read another site’s response headers when that site allows it through CORS, and almost no site exposes its security headers that way. A browser-based checker that “fetches” a URL would either see nothing or need its own server to send the request for you. Pasting keeps the whole check on your machine, and it works for intranet hosts, staging servers and homelab dashboards that the internet cannot reach.
The content security policy generator reads what you paste the way browsers read it:
- Commas start a new policy, so
default-src 'self', https://cdn.examplebecomes two policies and one broken directive. - Missing semicolons turn
script-srcinto a host name inside the directive before it. - Unquoted keywords such as
selfornonematch a host with that name, not your own site. - Leftover placeholders like
'nonce-{RANDOM}'are reported, and'strict-dynamic'without a valid nonce or hash is flagged, because it blocks every script. - Old syntax is caught too:
ALLOW-FROMin X-Frame-Options, Feature-Policy syntax inside Permissions-Policy, andSameSite=Nonecookies withoutSecure.
It also explains why Google recommends a nonce-based policy with 'strict-dynamic': an allowlist that trusts a whole public CDN lets an attacker load any script hosted there, and the analyzer names the risky hosts it finds.
Practical Use Cases
A few ways to put the content security policy generator to work, in a homelab or on a public site:
- 🛡️ Reverse proxy hardening. Add the Nginx lines to the server block of your proxy, or to the Advanced tab of an Nginx Proxy Manager host next to the rules from my CrowdSec with Nginx Proxy Manager guide. The generated comment explains the
add_headerinheritance rule, the usual reason headers go missing. - 🐳 Traefik in Docker. Copy the labels format into your compose file and attach the
security-headersmiddleware to each router. - 🌐 Apps you expose to the internet. Before you open a dashboard to the outside world, as in secure remote access to a home server, check that it sends HSTS,
nosniffand a CSP. - 📝 WordPress. If you run WordPress yourself, like in my WordPress and MariaDB on Docker guide, start with the Compatible preset and the WordPress/PHP output.
- 🔍 Audits after changes. Paste
curl -sIoutput before and after an upgrade or a proxy migration and compare the two scores.
Privacy, Ads, and Data Policy
- ✅ 100% free: no registration and no limits.
- ✅ No data storage: the content security policy generator never uploads your policies, headers or cookies, and the report does not even display cookie values.
- ✅ No ads in results: no watermarks and no tracking snippets added to your config.
- ✅ Client-side only: no external requests at all; the tool never contacts the sites you check.
Open Source and Self-Hosting
The content security policy generator is open source on GitHub: three files (index.html, style.css and script.js) with no external libraries and 67 unit tests, ready to drop onto any static web server. If you are hardening containers as well, see my notes on Docker security for self-hosting.
Like this content security policy generator, every tool on the Tools page runs in your browser, for example the JWT Token Decoder for session tokens and the Hash Generator for checksums.
Built by VahaC — 100% client-side, no data sent anywhere.
