Content-Security-Policy generator with stack presets and a checker
This tool builds a Content-Security-Policy from the directives you choose, with presets whose hosts come from each vendor's own documentation. It flags unsafe-inline, unsafe-eval, wildcards and a missing object-src, base-uri or frame-ancestors, and writes the header, Next.js, nginx, Apache or meta-tag version, in report-only mode if you want.
Updated
Policy check
No findings
Every check below passes for this policy.
- Pass · No 'unsafe-inline' for scriptsInline scripts are blocked unless they carry a nonce or hash.
- Pass · No 'unsafe-eval'eval() and friends are blocked.
- Pass · No wildcard or scheme-only sources for scripts and pluginsScript sources name specific hosts or nonces.
- Pass · object-src 'none'Plugins (<object>, <embed>) are blocked.
- Pass · base-uri setAn injected <base> tag can't redirect your relative script URLs.
- Pass · frame-ancestors setClickjacking protection is on (this replaces X-Frame-Options in modern browsers).
- Pass · form-action setForms can only submit to the hosts you list.
- Pass · default-src or script-src presentA baseline for scripts exists.
- Pass · No 'unsafe-inline' for stylesInline styles are blocked unless nonced or hashed.
Header
Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' blob: data:; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
- Header name
- Content-Security-PolicyViolations are blocked.
- Directives
- 10
- Policy length
- 207 characters
- Policy value
- default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' blob: data:; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
- A directive you add that has no entry yet starts from default-src's sources (here 'self'), so your own requests keep working next to the vendor hosts.
How does a Content-Security-Policy work?
A Content-Security-Policy is a list of directives, each naming a kind of resource (script-src, img-src, frame-src and so on) and the sources the browser may load it from. When the page asks for something the policy doesn't allow, the browser blocks it, or in report-only mode just reports it. The aim is to stop injected script from running even if an attacker finds a way to put markup on your page.
Fallbacks matter. default-src covers fetch directives you leave out, but base-uri, form-action and frame-ancestors do not fall back to it, and object-src only does if you rely on default-src. That is why the evaluator asks for each of them by name. A nonce ('nonce-…') or hash lets one specific inline script run while 'unsafe-inline' would let every inline script run; with 'strict-dynamic', trust passes from a nonced script to the scripts it loads, and host lists are ignored.
A <meta> tag can carry most of a policy, but the W3C draft says it can't carry frame-ancestors, report-uri or sandbox, and report-only policies need a real header. Vendor presets here use the hosts each vendor prints in its own documentation; where a vendor prints none (Razorpay), the preset is labelled a starting point and you should confirm it with report-only mode.
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-…' 'strict-dynamic'; object-src 'none'; base-uri 'self'; frame-ancestors 'none'
Where do the vendor presets come from?
| Preset | Vendor publishes a CSP list | Directives it adds | Source |
|---|---|---|---|
| Google Analytics 4 (gtag.js) | Yes | script-src: https://www.googletagmanager.com; img-src: https://www.googletagmanager.com https://*.google-analytics.com; connect-src: https://www.googletagmanager.com https://*.google-analytics.com https://*.google.com | https://developers.google.com/tag-platform/security/guides/csp |
| GA4 with Google Ads features (adds to GA4) | Yes | img-src: https://www.googletagmanager.com https://*.google-analytics.com https://*.google.com https://*.g.doubleclick.net; connect-src: https://www.googletagmanager.com https://*.google-analytics.com https://*.google.com https://*.g.doubleclick.net https://pagead2.googlesyndication.com; frame-src: https://www.googletagmanager.com | https://developers.google.com/tag-platform/security/guides/csp |
| Google Tag Manager | Yes | script-src: https://www.googletagmanager.com; img-src: https://www.googletagmanager.com; connect-src: https://www.googletagmanager.com https://www.google.com | https://developers.google.com/tag-platform/security/guides/csp |
| GTM custom JavaScript variables | Yes | script-src: 'unsafe-eval' | https://developers.google.com/tag-platform/security/guides/csp |
| Stripe.js and Elements | Yes | script-src: https://js.stripe.com https://*.js.stripe.com; frame-src: https://js.stripe.com https://*.js.stripe.com https://hooks.stripe.com; connect-src: https://api.stripe.com | https://docs.stripe.com/security/guide |
| Stripe Checkout (embedded) | Yes | script-src: https://checkout.stripe.com; frame-src: https://checkout.stripe.com; connect-src: https://checkout.stripe.com; img-src: https://*.stripe.com | https://docs.stripe.com/security/guide |
| Razorpay Checkout (starting point, see note) | No, starting point only | script-src: https://checkout.razorpay.com; frame-src: https://api.razorpay.com | https://razorpay.com/docs/payments/payment-gateway/web-integration/standard/build-integration/ |
| YouTube embeds (iframe) | Yes | frame-src: https://www.youtube.com | https://developers.google.com/youtube/iframe_api_reference |
| YouTube IFrame Player API script | Yes | script-src: https://www.youtube.com | https://developers.google.com/youtube/iframe_api_reference |
| Google Fonts | Yes | style-src: https://fonts.googleapis.com; font-src: https://fonts.gstatic.com | https://developers.google.com/fonts/faq |
How to add a Content-Security-Policy to your site
- 1Pick report-only and your stackChoose Content-Security-Policy-Report-Only, then the script style (plain, Next.js with nonces, or Next.js with 'unsafe-inline') and the vendors you load.
- 2Add your own hosts and a report endpointPut CDNs, APIs and other hosts in the extra box, one directive per line, and add an https report URL if you have a collector.
- 3Fix what the evaluator flagsWork through the high findings first: unsafe-inline and unsafe-eval in scripts, wildcards, and the missing object-src, base-uri and frame-ancestors.
- 4Deploy, watch, then enforceCopy the header, nginx, Apache or Next.js output, run it for a week on real traffic, add the hosts the reports name, then switch to the enforcing header.
Frequently asked questions
What is the difference between Content-Security-Policy and Content-Security-Policy-Report-Only?
Why does my Next.js CSP with a nonce break static pages?
Do I need 'unsafe-eval' in my policy?
Can a meta tag replace the CSP header?
Why are 'self' and 'none' written with quotes?
Why does 'strict-dynamic' make my host list stop working?
Sources
- W3C: Content Security Policy Level 3 (working draft) (checked 11 Nov 2026)
- MDN: Content-Security-Policy header (checked 11 Nov 2026)
- Next.js: How to set a Content Security Policy (checked 11 Nov 2026)
- Next.js: headers in next.config.js (checked 11 Nov 2026)
- Google: Use Tag Manager with a Content Security Policy (GA4 and GTM hosts) (checked 11 Nov 2026)
- Stripe: Integration security guide, Content Security Policy (checked 11 Nov 2026)
- Google: YouTube IFrame Player API reference (checked 11 Nov 2026)
- Google Fonts: Frequently asked questions (checked 11 Nov 2026)
- Razorpay: Standard Checkout build integration (no CSP list published) (checked 11 Nov 2026)
- Razorpay: Responsible disclosure (in-scope domains) (checked 11 Nov 2026)
- nginx: ngx_http_headers_module (add_header) (checked 11 Nov 2026)
- Apache: mod_headers (Header always) (checked 11 Nov 2026)
Need a custom dev tool for your team?
We build internal tools, dashboards, APIs, and SaaS platforms. If you can describe it, we can ship it.
Built by CountryDevs · No signup · No ads · We count visits, never what you enter