Security Tools
Content Security Policy (CSP) Generator
Build a Content-Security-Policy with source checks and risk warnings for each directive, then export it as a header, meta tag, Nginx, Apache or _headers rule.
How to use Content Security Policy (CSP) Generator
Edit the sources for each directive, add others such as media-src one per line, and set an optional report URL. Choose the output format, tick report-only or upgrade-insecure-requests if needed, and copy the line.
- Fill in the directivesEdit the sources for default-src, script-src, img-src and the rest; leave a box empty to omit it.
- Add extras and optionsAdd other directives one per line, a report-uri, upgrade-insecure-requests or report-only mode.
- Choose a format and copyPick HTTP header, meta tag, Nginx, Apache or a _headers file, read any warnings, then copy.
What the default policy allows
The starting policy is default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'. Scripts, fonts and API calls may only come from your own origin, images may also load from any HTTPS host or data URIs, inline styles are allowed, plugins are blocked and no other site can frame the page. Sources are checked as you type: an unquoted keyword such as self is corrected to 'self', and semicolons, commas or invalid hosts stop the output.
Warnings worth taking seriously
Allowing 'unsafe-inline' in script-src without a nonce, hash or 'strict-dynamic' lets injected inline scripts run, which removes most of the XSS protection a CSP offers; 'unsafe-eval' and broad sources such as *, https: or data: in script-src are flagged too. A meta tag can't carry frame-ancestors, report-uri or sandbox, and report-only mode only works as an HTTP header. Analytics, ads and third-party APIs usually need their domains in connect-src as well as script-src. Roll out in report-only mode first and watch the browser console.
Accuracy and data handling
A format or strength result covers only the checks shown here and does not replace a full security review or secure key management. The calculation runs in your current browser; the tool code does not send the input to a processing API.
FAQ
What is a Content Security Policy?
CSP is an HTTP response header that tells the browser which sources a page may load scripts, styles, images, frames and other resources from. A strict policy limits the damage of cross-site scripting (XSS).
How do I allow several third-party domains?
List them in the same directive, separated by spaces, for example 'self' https://a.example.com https://b.example.com. Each source is validated and duplicates are removed.
My site broke after adding a CSP. What now?
Open the browser console to see which resource was blocked and by which directive, then add that source. Trying report-only mode first lets you find these problems without blocking anything.
Should I use the meta tag or the HTTP header?
Prefer the header. The meta tag helps when you can't change server headers, but browsers ignore frame-ancestors, report-uri and sandbox in it, and it can't be used for report-only mode.
More Security Tools
Related toolsSign a message with HMAC-SHA256 or another hash, and verify webhook signatures.
Derive PBKDF2 keys with your own salt, iteration count, hash and output length.
Create prefixed random API keys and the SHA-256 hashes to store server-side.
Make cryptographically random PINs that skip 0000, 1234, years and dates.
Create easy-to-type passphrases from random words, with the entropy shown for each setting.
Create random one-time code samples and see how easy each length is to guess.