CSP Generator
Build a Content-Security-Policy from presets and per-directive sources — output as an HTTP header or a meta tag, with the framing warning included.
A Content-Security-Policy is a whitelist your server hands the browser with every page: which origins may supply scripts, styles, images, fonts, connections and frames, and whether the page itself may be framed. The builder here assembles directives in one fixed order — default-src, script-src, style-src, img-src, connect-src, font-src, media-src, object-src, frame-ancestors, base-uri, form-action — joins each directive’s sources with spaces and the directives with semicolons. Worked example: ticking default-src ’self’, script-src ’self’, style-src ’self’ and ’unsafe-inline’, img-src ’self’ and data:, and frame-ancestors ’none’ produces exactly “default-src ’self’; script-src ’self’; style-src ’self’ ’unsafe-inline’; img-src ’self’ data:; frame-ancestors ’none’” — no trailing semicolon, no invented directives.
Two warnings that matter. First, frame-ancestors is ignored in a meta tag — browsers only honour it in a real HTTP header, so clickjacking protection needs the header form. Second, a policy is a contract: if you ship script-src ’self’ while your pages load a script from a CDN, the browser will block that script. Test with the report-only header (Content-Security-Policy-Report-Only) on a staging copy before enforcing. Everything is assembled in page memory on this device; nothing you tick is sent anywhere or stored.
Quick answers
How do I build a Content-Security-Policy?
Pick sources per directive and join them: directives in a fixed order, sources space-separated, directives separated by semicolons. Ticking self for default and script, self + unsafe-inline for style, self + data: for images and none for framing gives “default-src ’self’; script-src ’self’; style-src ’self’ ’unsafe-inline’; img-src ’self’ data:; frame-ancestors ’none’”.
Start from the Strict or Balanced preset and adjust — then deploy as a header, report-only first, so violations surface before anything breaks.
What is a good strict CSP for a simple site?
Everything from your own origin, plugins and framing denied: default-src ’self’; script-src ’self’; style-src ’self’; img-src ’self’; connect-src ’self’; font-src ’self’; object-src ’none’; frame-ancestors ’none’; base-uri ’self’; form-action ’self’ — the Strict preset on this page, word for word.
It only works if the site truly loads nothing external and uses no inline scripts or styles; the Balanced preset is the fallback most real sites need.
How to use
- Start from a preset — Strict locks everything to your own origin and blocks plugins and framing; Balanced additionally allows inline styles, data: images and https: media, which most real sites need.
- Adjust per directive with the checkboxes: each directive (default-src, script-src, style-src, and so on) collects exactly the sources you tick, in a fixed directive order.
- Choose the output format: HTTP response header (the full-strength form) or HTML meta tag (weaker — browsers ignore frame-ancestors in a meta tag, and the page warns you).
- Copy the policy and deploy it — ideally first as Content-Security-Policy-Report-Only on staging, so the browser reports what would break before you enforce it.
About this tool
The two presets bracket the realistic range. Strict is the policy you would write for a site you fully control: everything from ’self’, objects blocked outright (object-src ’none’), framing denied, forms and base URIs pinned to your own origin. Balanced is the policy most production sites actually survive: inline styles allowed (style-src ’unsafe-inline’ — note this weakens style injection protection, not script protection), images from data: and any https: origin, fonts from https: and data:. What neither preset does is allow ’unsafe-inline’ or ’unsafe-eval’ for scripts — the moment script-src allows inline code, the policy stops being an XSS defence and becomes decoration. If a legacy page forces that choice, scope it to that page’s response rather than weakening the whole site, and treat removing the inline scripts as the real fix.
Frequently asked questions
Header or meta tag — which should I use?
The HTTP header, whenever you can set it. A meta tag cannot carry frame-ancestors (browsers ignore it there, so clickjacking protection silently vanishes), cannot use report-only mode or a report endpoint, and only applies from the point the tag is parsed. The meta form exists for static hosting where headers are genuinely unavailable.
Will a CSP break my site?
It will break exactly the things it forbids — which, on a first attempt, usually includes something you forgot: a CDN script, an inline event handler, a data: image. That is a discovery process, not a failure: run the same policy as Content-Security-Policy-Report-Only first, read the violation reports, adjust deliberately, then enforce.
What does ’unsafe-inline’ actually cost me?
For style-src, it allows inline style attributes and style elements — a modest weakening, since CSS injection is mostly a defacement and data-exfiltration risk. For script-src it is fatal to the policy’s purpose: any injected markup can run script, which is the attack CSP exists to stop. This generator therefore never puts it in script-src presets.
Why is there no report-uri or sandbox option?
Scope: this builder covers the eleven fetch and document directives site owners set daily, assembled exactly and in a stable order. Reporting endpoints involve a URL specific to your infrastructure, and sandbox is a separate per-page decision — both are better written by hand once the core policy is right than guessed by a form.
First time embedding? Read the step-by-step guide →
More free tools
Meta Tags Preview
Preview how your page looks on Google, X and Facebook — and grab the meta tags that make it look right.
Robots.txt Generator & Tester
Build a clean robots.txt, or paste yours in and check it for mistakes — including testing which crawler can fetch which URL.
UTM Builder
Tag your own outbound links with utm_source, medium and campaign — existing query strings and #anchors handled correctly.
QR Code Generator
Turn any link or text into a scannable QR code in seconds.
Word Counter
Count words, characters, sentences and reading time as you type.
Percentage Calculator
Work out percentages, increases and discounts in one click.