All tools Content Security Policy Generator ● Live Developer Tools

How Content Security Policy Generator works

  1. Enter your default-src value, e.g. 'self' to restrict to your own origin by default.
  2. Enter your img-src value if images load from external domains or data URIs.
  3. Enter your script-src value to control which scripts are allowed to run.
  4. Copy the generated Content-Security-Policy header string.
  5. Add it as a response header on your server or CDN, then test the site to confirm nothing is blocked unexpectedly.
  • Draft a starter CSP header for a static site that has never had one before.
  • Quickly generate a baseline policy to paste into a Cloudflare, Nginx, or Apache header config.
  • Understand how default-src, img-src, and script-src interact by seeing the assembled header.
  • Get a readable starting point to harden before a security review or audit.

The header string is built entirely in your browser from the values you enter. Nothing is sent to a server or stored.

  • Only default-src, img-src, and script-src are customizable; other directives use fixed baseline values.
  • Does not generate nonces, hashes, or a report-uri/report-to directive for CSP violation reporting.
  • The policy isn't validated against your live site — deploy it in report-only mode first to catch anything it would block.

Content Security Policy Generator

Content Security Policy Generator creates a practical baseline CSP header for static sites and simple web apps. It helps reduce unsafe defaults while keeping the policy readable.

Content Security Policy Generator Runs locally

Content Security Policy Generator

Build a starter CSP header for static sites and simple apps. Everything runs locally in this tab.

Output
Content-Security-Policy: default-src 'self'; script-src 'self'; img-src 'self' data: https:; style-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self'; frame-ancestors 'none';
Guide

How to use

  1. Enter your default-src value, e.g. 'self' to restrict to your own origin by default.

  2. Enter your img-src value if images load from external domains or data URIs.

  3. Enter your script-src value to control which scripts are allowed to run.

  4. Copy the generated Content-Security-Policy header string.

  5. Add it as a response header on your server or CDN, then test the site to confirm nothing is blocked unexpectedly.

Scenarios

Use cases

  • Draft a starter CSP header for a static site that has never had one before.

  • Quickly generate a baseline policy to paste into a Cloudflare, Nginx, or Apache header config.

  • Understand how default-src, img-src, and script-src interact by seeing the assembled header.

  • Get a readable starting point to harden before a security review or audit.

Good to know

Limitations & Privacy

Private by design

The header string is built entirely in your browser from the values you enter. Nothing is sent to a server or stored.

  • Only default-src, img-src, and script-src are customizable; other directives use fixed baseline values.

  • Does not generate nonces, hashes, or a report-uri/report-to directive for CSP violation reporting.

  • The policy isn't validated against your live site — deploy it in report-only mode first to catch anything it would block.

FAQ

Frequently asked questions

Is Content Security Policy Generator free to use?

Yes. The tool is free and runs directly in your browser with no account required.

Does this tool upload my data?

No. The header string is assembled locally in the browser tab and is not sent to a server.

What is this tool best for?

Producing a readable starting-point CSP header for a static site or simple web app, rather than writing every directive from scratch.

Which directives can I customize?

You set default-src, img-src, and script-src directly. The tool fills in reasonable fixed values for style-src, object-src, base-uri, and frame-ancestors so the policy is complete.

Why is style-src fixed to 'self' 'unsafe-inline'?

Allowing inline styles keeps the starter policy from breaking common inline style attributes. For a stricter policy, remove 'unsafe-inline' once you've moved styles to external stylesheets or added nonces.

Do I need to test the policy before deploying it?

Yes. Any CSP can block scripts, images, or fonts your site actually needs. Deploy it first as a Content-Security-Policy-Report-Only header, or test in a staging environment, before enforcing it in production.

Where do I add the generated header?

Add it as an HTTP response header from your web server or CDN config (Apache, Nginx, Cloudflare, etc.) — this tool only generates the header value, it does not apply it to a live site.

Does it cover every CSP directive?

No — it's a practical baseline covering the most commonly needed directives. Advanced use cases (nonces, hashes, report-uri, worker-src, etc.) need to be added manually to the generated string.