Shiklo Tools
PDF40
Image20
Calculators & Converters25
Text & Writing13
Developer26
Video14
Audio14
Document14
Data & Spreadsheet12
Web & SEO9
OCR & Scanning5
Archive & File12
Security & Privacy23
Health & Medical29
QR & Barcode5

CSP Generator

Build a Content-Security-Policy header or meta tag from a strict starting point, and check any policy for common weaknesses.

A Content-Security-Policy (CSP) tells the browser exactly where a page may load scripts, styles, images, fonts and other resources from, and which sites may embed it. A good policy is the strongest defence against cross-site scripting (XSS): even if an attacker manages to inject a script tag, the browser refuses to run it. Writing a policy by hand, though, means remembering dozens of directives and keyword spellings.

This generator starts from a strict, sensible policy — everything from your own site only, no plug-ins, no framing, no form posts elsewhere — and lets you add the sources you need for each directive with quick buttons or by typing hosts. It outputs the policy as an HTTP header, a report-only header for testing, or a meta tag, and checks your policy as you build it. You can also paste any existing policy to see its weaknesses. Everything runs in your browser.

How to use CSP Generator

  1. Start from the strict starting point.
  2. Add the hosts and keywords each directive needs, such as a CDN in script-src.
  3. Choose the output: HTTP header, report-only header or meta tag.
  4. Copy the policy, deploy it in report-only mode first, then enforce it.

Features

  • All main directives: default-src, script-src, style-src, img-src, connect-src, frame-ancestors and more.
  • Strict starting point and quick source buttons.
  • HTTP header, report-only header or meta tag.
  • Optional report URL and upgrade-insecure-requests.
  • Live checks for unsafe-inline, unsafe-eval, wildcards and missing directives.
  • Check any existing policy by pasting it.
  • Runs in your browser; nothing is sent.

The key directives

Fetch directives control where each kind of resource may come from; default-src is the fallback for those you don't set. A few directives protect against other attacks.

DirectiveControls
default-srcFallback for all resource types
script-srcJavaScript — the most important one
style-srcStylesheets and inline styles
img-src, font-src, media-srcImages, fonts, audio and video
connect-srcfetch, XMLHttpRequest and WebSocket targets
object-srcOld plug-in content; set to 'none'
base-uriThe base element, used to redirect relative URLs
frame-ancestorsWhich sites may embed the page (clickjacking)

What the checks look for

The checks flag the weaknesses that make a policy easy to bypass. Allowing 'unsafe-inline' scripts without nonces or hashes lets injected inline scripts run, which defeats most of the point of CSP. 'unsafe-eval' allows code built from strings. Wildcards such as * or https: in script-src allow scripts from any site, including ones an attacker controls. A missing object-src, base-uri or frame-ancestors leaves well-known bypasses open, and plain http: sources can be tampered with in transit.

Rolling out a policy safely

A strict policy will often break something at first — an analytics snippet, an embedded video, an inline script. Start with the report-only header, which only reports what would be blocked, watch the browser console or your report URL for a few days, add the sources that are really needed, and then switch to the enforced header. Prefer nonces or hashes over 'unsafe-inline' for inline scripts, and avoid broad host lists when a single CDN path will do.

Header or meta tag?

Sending the policy as an HTTP response header is best: it applies before any HTML is parsed and supports every directive. A meta tag is handy when you can't change server headers, such as on some static hosts, but frame-ancestors, report-uri and sandbox don't work in meta tags, so the tool leaves them out and tells you. Set headers in your web server, CDN, hosting dashboard or framework middleware.

Related tools

Check which security headers your site already sends with the Security Headers Checker, add Subresource Integrity hashes to CDN scripts with the SRI Hash Generator, and control browser features such as the camera and microphone with the Permissions-Policy Generator.

Frequently asked questions

How do I create a Content-Security-Policy?

Start from the strict starting point, add the sources your site needs, and copy the header.

What is a good starting CSP?

default-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none' — then add what your site needs.

Why is 'unsafe-inline' bad?

It lets injected inline scripts run. Use nonces or hashes instead.

Can I check an existing CSP?

Yes. Paste it into Check an existing policy.

Should I use a header or a meta tag?

A header when possible; meta tags don't support frame-ancestors or reporting.

How do I test a policy without breaking my site?

Use the report-only header first and watch what would be blocked.

Is anything sent to a server?

No. The tool runs in your browser.

Related tools