Tools

Home
JSON FormatterSQL FormatterJS ValidatorMeta Tag Generator
Robots.txt Generator.htaccess GeneratorSchema Generator
JPG to PNGPNG to WebPCrop Image

CSP Generator

Build a Content Security Policy header visually — configure directives, add sources, and copy the output instantly

Your files never leave your browser
Quick Presets

Select a preset to quickly populate common directives, then customise below.

DirectivesToggle to enable
Generated Output
Enable at least one directive to generate your CSP...

Build a Content Security Policy header by toggling directives, clicking source values like 'self' and 'unsafe-inline', and grabbing the finished output as an HTTP header, meta tag, or Report-Only header. Pick a preset for Google Analytics, Stripe, or CDN setups — or start from scratch and add sources one by one.

The policy string updates live as you make changes. Copy it straight into your server config or HTML head. And everything runs in your browser. Nothing gets uploaded.

How It Works

Toggle Directives
→
Add Sources
→
Copy CSP Output

Left panel has every CSP directive — script-src, style-src, font-src, the works. Flip one on, add sources with the helper buttons or type a domain yourself. The right panel rebuilds the full policy string in real time. Pick your output format and hit Copy. Takes two seconds.

Examples

Simple Blog — Self-Hosted Everything

No third-party scripts, no CDN. Just your own files. Quick.

INPUT
default-src: 'self' script-src: 'self' style-src: 'self' img-src: 'self'
OUTPUT
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self'

Marketing Site — Google Analytics + Google Fonts

The setup that trips everyone up. Google has multiple subdomains to allow, and Fonts injects CSS that needs 'unsafe-inline'. So you end up with a longer policy than you'd expect for something this common.

INPUT
default-src: 'self' script-src: 'self' https://www.googletagmanager.com https://www.google-analytics.com style-src: 'self' 'unsafe-inline' https://fonts.googleapis.com font-src: https://fonts.gstatic.com img-src: 'self' https://www.google-analytics.com data: connect-src: 'self' https://www.google-analytics.com
OUTPUT
Content-Security-Policy: default-src 'self'; script-src 'self' https://www.googletagmanager.com https://www.google-analytics.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src https://fonts.gstatic.com; img-src 'self' https://www.google-analytics.com data:; connect-src 'self' https://www.google-analytics.com

E-Commerce Checkout with Stripe

Stripe loads JS from their CDN and iframes the payment form. Miss one domain and checkout just... breaks. No error on screen. And good luck figuring out which directive blocked it without checking DevTools.

INPUT
default-src: 'self' script-src: 'self' https://js.stripe.com frame-src: https://js.stripe.com connect-src: 'self' https://api.stripe.com
OUTPUT
Content-Security-Policy: default-src 'self'; script-src 'self' https://js.stripe.com; frame-src https://js.stripe.com; connect-src 'self' https://api.stripe.com

Who Uses This

👨‍💻 Web Developers

Build a CSP from scratch for new projects or debug why a widget broke after a policy change.

🛡️ Security Engineers

Tighten an existing policy after a pen test flags 'unsafe-inline' or overly broad wildcards.

⚙️ DevOps / SREs

Generate Report-Only headers to audit what production actually loads before locking things down.

🎓 Students

Toggle directives and watch the output change — fastest way to learn what each one controls.

Common Mistakes

Forgetting to quote keyword values

Writing script-src self without quotes means the browser reads "self" as a literal domain name. It has to be 'self' with single quotes. And same for 'none', 'unsafe-inline', all of them. The buttons here add quotes automatically, so that's one less thing to mess up.

Setting default-src * and calling it done

default-src * allows any domain, but it still blocks inline scripts and eval(). People deploy it, assume everything is fine, then spend an hour on why inline event handlers won't fire. Not great. Be specific about what you actually need.

Skipping Report-Only before going live

Pushing an enforcing CSP straight to production is how fonts vanish, analytics dies, and embedded videos go blank. Start with Content-Security-Policy-Report-Only. Monitor violations for a week. Patch the gaps. Then flip to enforcing.

Technical Details

Frequently Asked Questions

What is a Content Security Policy and why do I need one?

CSP is an HTTP header that tells browsers which sources — scripts, styles, images, fonts — are allowed to load on your page. Without one, any XSS vulnerability gives an attacker free rein to run whatever code they want. Think of it as a bouncer list for your site. Even if bad HTML sneaks in, the browser won't execute code from origins you didn't approve.

What's the difference between Content-Security-Policy and Report-Only?

The enforcing header blocks anything that breaks the rules. Report-Only just logs violations to the console (or a reporting endpoint) but doesn't actually block anything. So you can see what would break before it does. Use Report-Only when rolling out a new policy — that way you catch problems before real users do.

Can I use a meta tag instead of an HTTP header?

Yes. Add <meta http-equiv="Content-Security-Policy" content="..."> inside your <head> and it works for most directives. But there's a catch — frame-ancestors and report-uri are ignored in meta tags. If you need those two, the header has to come from the server. No way around it.

How do I add a CSP header in Nginx or Apache?

Nginx: put add_header Content-Security-Policy "your-policy"; inside the server or location block. Apache: use Header set Content-Security-Policy "your-policy" in .htaccess or your virtual host config. Copy the HTTP Header output from this tool and paste the value between the quotes. That's it.

Why is my CSP blocking something I already allowed?

Almost always, the domain is in the wrong directive. A script loading from cdn.example.com needs script-src, but if that script fetches data, the API domain also needs to be in connect-src. Open DevTools — CSP violations show up in the console with the exact directive that blocked the request. Start there.

Share: