CSP Generator

Build a Content-Security-Policy header from presets or your own sources for each directive, with warnings about unsafe-inline, wildcards and missing directives.

Processed on your device. Files are not uploaded

How to build a Content-Security-Policy

  1. Pick a preset or fill in sources

    Each directive controls where one kind of content may come from.

  2. Read the warnings

    Risky choices are pointed out.

  3. Copy the header

    Also available as a meta tag.

Worked example

This is what CSP Generator gives for its own sample values. Open the tool above and change anything to try your own.

Start from
The values below
default-src
'self'
script-src
'self'
style-src
'self' 'unsafe-inline'
img-src
'self' data: https:
font-src

Content-Security-Policy

default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; object-src 'none'; frame-ancestors 'self'; base-uri 'self'; form-action 'self'

As an HTML meta tag (frame-ancestors and report-uri do not work here)

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

About CSP Generator

Build a Content-Security-Policy header, which limits where scripts, styles, images and frames can load from and so reduces the damage of cross-site scripting. Warnings flag unsafe-inline, unsafe-eval, wildcards and missing directives.

FAQs

Where do I start?

Begin with the Basic preset and send it as Content-Security-Policy-Report-Only to see what it would block.

Why avoid unsafe-inline?

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

Can I use a meta tag?

Yes, but frame-ancestors and report-uri only work in the header.

Related tools