Content Security Policy Builder
Build a Content Security Policy with clickable sources, check it for weak spots, test it against real page HTML and copy the header for your server.
Draait in je browser. Je bestanden verlaten je apparaat nooit. Zie hoe je dit controleert
…
Zo doe je het
- 1Start from the default
The builder opens with a safe base policy; edit or remove cards and add directives from the menu.
- 2Add services
Choose a service such as Google Analytics or Stripe in Allow a service to add its documented sources.
- 3Add your hosts
Type hosts or schemes in the field under a card and press Add; click a chip to toggle a keyword.
- 4Read the findings
Fix high findings first, for example by adding object-src 'none' or switching to nonce-based scripts.
- 5Test on your HTML
Paste page source and URL in the Test tab, press Test the policy and review every blocked line.
- 6Copy the server config
In Deploy choose your server, add a report endpoint if needed and copy or download the snippet.
Over deze tool
A Content Security Policy tells the browser which scripts, styles, images, frames and connections a page may use. A good policy stops most cross-site scripting attacks from doing harm, because an injected script that does not come from an allowed source, or does not carry the right nonce or hash, simply never runs. Writing a policy by hand is fiddly: one missing font host breaks the design, one wildcard makes the whole policy useless. This builder shows every directive as a card with keyword switches such as 'self', 'none' and 'strict-dynamic', lets you add hosts with one field, and adds the documented sources for popular services in one click. A strength score and a list of findings point out the classic mistakes, and the test tab runs your policy against pasted page HTML the same way a browser would, so you see exactly what would be blocked before you deploy.
Who this is for
Web developers, DevOps engineers and site owners who need a CSP header for a security audit, a penetration-test finding or a compliance checklist, and anyone who wants to tighten an existing policy without breaking the site.
Building the policy
Each directive card explains what it controls. Keyword chips toggle 'self', 'none', 'unsafe-inline', 'unsafe-eval', 'strict-dynamic', 'unsafe-hashes', 'wasm-unsafe-eval' and 'report-sample'; only the keywords that make sense for that directive are offered. Type hosts, schemes such as data: or blob:, wildcards like *.example.com or full path sources into the field under each card. The Allow a service menu adds the sources published by Google for Analytics 4 and Tag Manager, by Stripe, PayPal, Cloudflare Turnstile, reCAPTCHA, YouTube, Vimeo, Google Fonts, jsDelivr, cdnjs and Sentry. Nonce-based scripts adds a random 128-bit nonce together with 'strict-dynamic', the approach recommended by the CSP specification for modern sites.
Findings and strength score
The evaluator follows the checks of Google's CSP Evaluator and the OWASP cheat sheet: inline scripts allowed without a nonce, eval allowed, wildcard or https: script sources, data: in script-src, missing object-src 'none', missing base-uri, missing frame-ancestors and form-action, deprecated report-uri, and hosts known to serve JSONP or old libraries that can bypass allowlists. In meta mode it also warns that frame-ancestors, sandbox and reporting are ignored in a meta tag.
Testing against real HTML
Paste the source of a page and the address it is served from. The tester finds every script, stylesheet, image, srcset entry, iframe, object, form action, base tag, inline style block, style attribute, event handler and javascript: link. For each one it applies the directive fallback chain of CSP Level 3 (for example script-src-elem, then script-src, then default-src), compares the URL with each source expression, honours nonces and hashes, and explains the result. Inline blocks that are blocked show their SHA-256 hash so you can allow exactly that code. Allow everything that was blocked turns the failures into sources in one step, and Generate policy from this page builds a starting policy from scratch.
Deploying safely
The deploy tab writes the header for nginx, Apache, Netlify and Cloudflare Pages, vercel.json, Next.js, Express with helmet and IIS, or a meta tag. Report-only mode switches the header name so the browser only reports violations. Add a report endpoint and a report-to group to also get a Reporting-Endpoints header.
Worked example
A shop page loads its own CSS, Google Fonts, a gtag script and one inline gtag snippet. Starting from default-src 'self', the test shows 3 blocked items: the fonts stylesheet, the googletagmanager.com script and the inline snippet with hash sha256-…. Adding the Google Fonts and Google Analytics presets and the hash brings the result to 0 blocked, and the score rises from 72 to 90 once frame-ancestors 'self' is added.
Limits
The tester reads static HTML; it does not run your JavaScript, so scripts that a loader adds later, fetch calls and dynamically created frames are not tested. Check those in report-only mode in a real browser. Browser support for newer directives differs, and a policy is not a replacement for escaping user input.
Uitgewerkt voorbeeld
default-src 'self' + Google Fonts preset + one hash: 3 blocked resources become 0; score 72 → 90 after adding frame-ancestors 'self'.
In het kort
- Categorie: Ontwikkelaar & data
- Draait in je browser, geen registratie, geen upload.
- De gegevens die je invoert blijven op je apparaat.
- Beschikbaar in het Engels.
- Inhoud voor het laatst gecontroleerd:
- Officiële bron: W3C Content Security Policy Level 3
Veelgestelde vragen
Should I start with report-only mode?
Yes. Send Content-Security-Policy-Report-Only for a few days, look at the reports or the browser console, fix what would break, then switch to the enforcing header.
Why is 'unsafe-inline' ignored in my policy?
When script-src contains a nonce, a hash or 'strict-dynamic', browsers ignore 'unsafe-inline' on purpose. It stays in the policy only as a fallback for very old browsers.
What is 'strict-dynamic'?
It lets a script that was trusted by its nonce or hash load further scripts, while host allowlists are ignored. It makes nonce-based policies practical for sites that use loaders such as Tag Manager.
Can I put frame-ancestors in a meta tag?
No. frame-ancestors, sandbox and the reporting directives only work in an HTTP header; the builder warns you when the meta output is selected.
How do I get the hash of an inline script?
Use the hash box or the test tab. The hash covers the exact text between the script tags, so any change, even whitespace, needs a new hash.
Is my page HTML uploaded?
No. Parsing, hashing with Web Crypto and testing all run in your browser, and the policy is saved only in local storage.
