Skip to main content

CSP Generator - build a Content-Security-Policy header

Build a Content-Security-Policy from directive toggles, get the header line, meta tag and Nginx snippet, with live unsafe-inline warnings, browser-only

  • Runs locally
  • Category Developer & DevOps
  • Best for Checking file type, size, metadata, and obvious mismatch signals before sharing.

Observe violations without blocking — use during rollout

default-src
script-src
style-src
img-src
connect-src
font-src
frame-src
object-src
base-uri
form-action
frame-ancestors

No risky sources detected.

Content-Security-Policy: default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'">

frame-ancestors, report-uri and sandbox only work as a response header, not in <meta>.

add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; font-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;

What this tool does

A Content Security Policy generator that builds the header from choices instead of asking you to memorize syntax. Toggle sources on each directive ('self', 'none', 'unsafe-inline', 'unsafe-eval', https:, data:), paste your own CDN or API domains, and watch the policy assemble in real time. The tool emits three drop-in forms at once: a raw Content-Security-Policy header line, an HTML meta http-equiv tag, and an Nginx add_header directive, each with one-click copy. Three presets cover the common starting points: a strict same-origin lockdown, a permissive set that allows jsdelivr, unpkg and Google Fonts, and a report-only policy for observing violations before you enforce. Whenever a choice weakens the policy, such as 'unsafe-inline' on script-src or a bare https: wildcard, an inline warning explains why and what to use instead. Everything runs in your browser, nothing is uploaded, and the policy round-trips through a shareable URL.

Tool details

Input
Files + Text
The page exposes text boxes, numeric controls, file pickers, or structured inputs depending on the tool.
Output
Live result + Copy
The result area focuses on usable output, with copy, download, or preview actions when supported.
Privacy
Browser-side processing
The main tool logic does not call an external API, so inputs normally stay in the current tab.
Save / share
Shareable URL state
Key settings are encoded in the URL so another person can reopen the same setup.
Performance budget
Initial JS <= 9 KB
No WASM budget is declared, keeping the tool quick to open on mobile.
Best fit
Developer & DevOps · Developer
Category and role tags drive related tools, internal links, and quick fit checks.

How to use

  1. 1. Input

    Paste or drop your content into the tool panel.

  2. 2. Process

    Click the button. All processing is local in your browser.

  3. 3. Copy / Download

    Copy the result or download to disk in one click.

How CSP Generator fits into your work

Use it before upload, handoff, archive, support review, or any moment where a file needs one local check before it leaves your machine.

File jobs

  • Checking file type, size, metadata, and obvious mismatch signals before sharing.
  • Preparing mixed folders for upload, archive, intake, or review.
  • Keeping sensitive files in the browser instead of sending them to an account-based service.

File checks

  • Do not treat the extension alone as proof of the real file type.
  • Review metadata before a file goes to customers, vendors, or a public page.
  • Keep the original file until the copied, converted, or exported result is verified.

Good next steps

These links move the current task into a more complete workflow.

  1. 1 CSP Policy Auditor Inspect Content-Security-Policy directives for unsafe sources, missing fallbacks, framing gaps, object-src, base-uri, and reporting coverage. Open
  2. 2 HTTP Security Header Auditor Audit raw response headers for HSTS, CSP, cookie flags, MIME sniffing, clickjacking, referrer, and permissions policy gaps. Open
  3. 3 Meta Tag Generator Generate SEO meta tags — title, description, Open Graph, Twitter Card, Schema.org. Open

Real-world use cases

  • Ship a first CSP on a new app

    You are launching a single-page app and want a baseline policy before go-live. Start from the strict preset, add your API origin to connect-src and your CDN to script-src, and copy the header line into your server config. You get a working default-src 'self' policy in under a minute instead of hand-typing directives and discovering typos in production.

  • Whitelist a third-party widget

    Marketing just added an analytics snippet and a chat widget, and the console is full of CSP violations. Paste the widget's domains into the relevant directives (script-src for its JS, connect-src for its API, frame-src if it embeds an iframe), regenerate, and ship the updated header. The live warnings remind you not to widen script-src to a bare https: wildcard just to make the errors go away.

  • Stage a report-only rollout

    You inherited a legacy site with inline scripts everywhere and cannot risk breaking it. Use the report-only preset to emit a Content-Security-Policy-Report-Only header, wire up a report endpoint, and collect violations for a week. Fold each legitimate source into the policy here, then flip to the enforcing header name once the reports go quiet.

  • Generate the right form for static hosting

    Your site is on a static host where you cannot set response headers, so you need the meta-tag form instead. Build the policy, copy the <meta http-equiv> output, and drop it into the document head. The note under the meta output reminds you that frame-ancestors will not work there, so you handle clickjacking another way.

Common pitfalls

  • Leaving 'unsafe-inline' on script-src to silence console errors. It re-opens the XSS hole CSP was meant to close. Move inline code into files, or authorize it with a per-request nonce or a sha256 hash instead.

  • Forgetting default-src, so unlisted directives silently allow everything. A policy of just script-src 'self' still lets images, fonts and connections load from anywhere. Always set default-src 'self' as the baseline and override per directive.

  • Putting frame-ancestors or report-uri in a <meta> tag. Those are header-only directives and the browser ignores them in meta. Use the response-header output for anything beyond the basic fetch directives.

Privacy

The whole generator is plain JavaScript running in your browser tab. Directive choices, custom domains and the generated policy never leave the page, and there is no analytics on what you build. The one thing to know: the shareable URL encodes your policy in the query string, so a link pasted into chat records those directives in the recipient server's access log. A CSP is not secret, but if it reveals internal asset hosts you would rather keep quiet, use the copy button instead of sharing the URL.

FAQ

Tool combos

Folks in your role tend to reach for these alongside this tool.

Made by Toolora · 100% client-side · Updated 2026-05-29