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

Start in report-only mode on a live site, read the reports for a week, then switch to enforcing.

The Next.js options follow the policies in the Next.js CSP guide. Nonces make every page render per request.

Adds 'unsafe-eval', which Google says these variables need.

Razorpay publishes no CSP list, so check it in report-only mode.

frame-ancestors has no fallback to default-src, so it must be set explicitly. Replace it with your own list in the extra box if a partner frames you.

One directive per line. Sources are added to what the choices above produce. Write keywords with single quotes, such as 'self'.

Optional. Adds report-uri and report-to, plus the Reporting-Endpoints header that report-to needs.

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?

Each preset's hosts and the page they were read from (checked 2026-11-11)
PresetVendor publishes a CSP listDirectives it addsSource
Google Analytics 4 (gtag.js)Yesscript-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.comhttps://developers.google.com/tag-platform/security/guides/csp
GA4 with Google Ads features (adds to GA4)Yesimg-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.comhttps://developers.google.com/tag-platform/security/guides/csp
Google Tag ManagerYesscript-src: https://www.googletagmanager.com; img-src: https://www.googletagmanager.com; connect-src: https://www.googletagmanager.com https://www.google.comhttps://developers.google.com/tag-platform/security/guides/csp
GTM custom JavaScript variablesYesscript-src: 'unsafe-eval'https://developers.google.com/tag-platform/security/guides/csp
Stripe.js and ElementsYesscript-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.comhttps://docs.stripe.com/security/guide
Stripe Checkout (embedded)Yesscript-src: https://checkout.stripe.com; frame-src: https://checkout.stripe.com; connect-src: https://checkout.stripe.com; img-src: https://*.stripe.comhttps://docs.stripe.com/security/guide
Razorpay Checkout (starting point, see note)No, starting point onlyscript-src: https://checkout.razorpay.com; frame-src: https://api.razorpay.comhttps://razorpay.com/docs/payments/payment-gateway/web-integration/standard/build-integration/
YouTube embeds (iframe)Yesframe-src: https://www.youtube.comhttps://developers.google.com/youtube/iframe_api_reference
YouTube IFrame Player API scriptYesscript-src: https://www.youtube.comhttps://developers.google.com/youtube/iframe_api_reference
Google FontsYesstyle-src: https://fonts.googleapis.com; font-src: https://fonts.gstatic.comhttps://developers.google.com/fonts/faq

How to add a Content-Security-Policy to your site

  1. 1
    Pick 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.
  2. 2
    Add 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.
  3. 3
    Fix 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.
  4. 4
    Deploy, 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?
The first blocks anything the policy doesn't allow. The second only sends reports (to report-uri or report-to) and blocks nothing, so you can see what a policy would break on real traffic. You can send both at once, with the enforcing one looser and the report-only one stricter, while you tighten the policy.
Why does my Next.js CSP with a nonce break static pages?
Next.js applies the nonce while rendering each request, from the CSP header that request carries. Static pages are built before any request exists, so they have no nonce. The Next.js guide says nonce-based CSP requires dynamic rendering for all pages, disables ISR and static optimisation, and is incompatible with Partial Prerendering. Its experimental Subresource Integrity option is the documented alternative if you need static generation.
Do I need 'unsafe-eval' in my policy?
Usually not in production. The Next.js guide says React uses eval in development to rebuild server error stacks in the browser, so 'unsafe-eval' is needed in development only. Google Tag Manager's custom JavaScript variables are another case that needs it. If neither applies, leave it out and test.
Can a meta tag replace the CSP header?
For most directives, yes, but not all. The W3C draft says frame-ancestors, report-uri and sandbox are not supported in a meta element, and the report-only header isn't either. That means a meta policy cannot stop clickjacking or send reports. Use an HTTP header whenever your host lets you set one.
Why are 'self' and 'none' written with quotes?
Keywords in a CSP are quoted with single quotes: 'self', 'none', 'unsafe-inline'. Without quotes the browser reads self as a host called self. This tool rejects unquoted keywords in the extra box and says which one is wrong.
Why does 'strict-dynamic' make my host list stop working?
MDN says that when 'strict-dynamic' is present, host sources, scheme sources, 'self' and 'unsafe-inline' in that directive are ignored by browsers that support it. Scripts run only if they carry a nonce or hash, or were loaded by a script that does. So a third-party script must be loaded by a nonced script, such as a <Script nonce> tag.

Sources

Related tools

See all 135 free tools

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