Content Security Policy (CSP) generator
A Content Security Policy tells browsers which sources a page may load scripts, styles, images and other content from, which limits the damage of cross-site scripting. Start from a strict policy and edit each directive’s sources, such as 'self', https://cdn.example.com or a nonce, and the generator writes the policy as an HTTP header, a meta tag, or a line for nginx, Apache or Caddy. As you edit, it checks the policy for unquoted keywords, invalid sources, 'unsafe-inline', 'unsafe-eval', wildcards and missing object-src, base-uri and frame-ancestors.
Separate sources with spaces. Keywords need single quotes, such as 'self' and 'none'. Leave a directive empty to omit it.
More directives and reporting
Output
Findings
No problems found.
How to use the CSP Generator
- 1
Start from the strict policy
The starter allows only your own origin and blocks plugins and framing.
- 2
Add your sources
Type each directive’s allowed sources separated by spaces, for example 'self' https://cdn.example.com.
- 3
Choose the output
Pick HTTP header, meta tag, nginx, Apache or Caddy. Tick Report-Only to test first.
- 4
Fix findings
Read the findings below the output and remove anything marked High.
- 5
Deploy
Add the header to your server or CDN and watch the browser console for blocked content.
When to use it
- Write a first CSP for a website that has none.
- Allow a new analytics or CDN host without weakening the whole policy.
- Produce a Report-Only header to test a policy on a live site.
Limits
- The generator cannot see your pages, so it cannot list the sources they actually load. Test with Report-Only and the browser console.
- Nonces must be random for every response; the generator only writes the placeholder you type.
- Security findings are heuristics based on common CSP bypasses, not a full audit.
Privacy
The policy is built in your browser. Nothing you type is sent anywhere.
Frequently asked questions
Is 'unsafe-inline' really that bad?
For scripts, yes: it allows any inline script, including one injected by an attacker, which removes most of the protection CSP gives against cross-site scripting. Use nonces or hashes instead. For styles it is a much smaller risk.
What is the difference between the header and the meta tag?
Both set a policy, but the meta tag cannot use frame-ancestors, report-uri, report-to or sandbox, and it only applies to content after it in the page. The HTTP header is preferred.
What does Report-Only do?
Content-Security-Policy-Report-Only reports violations without blocking anything, so you can test a policy on a live site before enforcing it.
What is 'strict-dynamic'?
With a nonce or hash, it lets scripts loaded by trusted scripts run too, and makes browsers ignore host allowlists. It is the basis of the strict CSP that Google recommends.
Why set object-src 'none' and base-uri?
object-src 'none' blocks old plugin content such as Flash, which can bypass script rules. base-uri stops an injected base tag from redirecting your relative script URLs.
Where do I put the header?
In your web server or CDN configuration so every HTML response carries it. The nginx, Apache and Caddy outputs are ready to paste into the site’s configuration.
Related tools
- CSP ValidatorChecks a pasted CSP header for syntax errors and common weaknesses, ranked by severity.
- SRI Hash Generatorsha384 integrity hashes and ready-made script and link tags, plus an integrity checker.
- security.txt GeneratorCreates a valid RFC 9116 security.txt file so researchers know how to report vulnerabilities.
People also use
- Phishing URL CheckerCheck a suspicious link for phishing tricks such as look-alike brand names and punycode, without opening it.
- SSH Key GeneratorMake an Ed25519 or RSA SSH key pair in OpenSSH format, with its fingerprint, without installing anything.
- 2FA / TOTP Code GeneratorGet 6-digit 2FA codes from a secret or QR code, create test secrets and check codes, all in your browser.
- Bcrypt & Argon2 Hash GeneratorCreate and check bcrypt and Argon2 password hashes, with parameters compared to OWASP guidance.
Last updated November 22, 2026 · How we build and test our tools