CSP BUILDER

Build a Content-Security-Policy you can ship

Start from a strict policy, tick the services your pages use and copy the header. You also get the other headers a security review looks for, in the format your server uses.

Build your policy

It starts strict: only your own site, no plugins, no framing, forms to yourself, and http upgraded to https. Add what your pages really load.

Services your pages use
Add your own sources

Hosts like https://cdn.example.com, one or more per box, separated by spaces. Keywords such as self get their quotes added for you.

An https address that collects reports. Needed to learn from report-only mode.

Header: Content-Security-Policy-Report-Only
Content-Security-Policy-Report-Only: default-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests
As a meta tag
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; upgrade-insecure-requests">

A meta tag cannot be report-only, so it enforces the policy. A meta tag ignores frame-ancestors, so we left it out. Use the header when you can, because frame-ancestors only works as a header.

Add it to your server, with the other security headers

  • Strict-Transport-Security: max-age=31536000; includeSubDomainsBrowsers stay on https for a year. Turn it on once every subdomain serves https.
  • X-Content-Type-Options: nosniffStops browsers guessing a file type and running an upload as a script.
  • Referrer-Policy: strict-origin-when-cross-originOther sites see your domain, never the full page address.
  • Permissions-Policy: camera=(), microphone=(), geolocation=()Switches off browser features the site does not use.
nginx config
add_header Content-Security-Policy-Report-Only "default-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;

How it works

The starting policy allows only your own site, blocks plugins, stops other sites from framing yours, limits forms to your own address and upgrades http requests to https.

Nonce or hash, in plain words

Some pages have scripts written straight into the HTML. A policy that blocks those would break the page, and allowing all of them removes most of the protection. A nonce is a random value your server makes for every page view. You put it on your own script tags and in the policy, so only scripts with the right value run. A hash is a fingerprint of one fixed script. It works when the script never changes.

Roll it out safely

  1. Keep report only on and send the header for a week.
  2. Read the reports, or the browser console, and add the hosts that were wrongly flagged.
  3. Turn report only off and send the real header.

Sources are taken from each vendor’s own guidance. If a service you use is not listed, add its hosts under Add your own sources.

Check your domain now

See how your SPF, DMARC, security headers and security.txt look from the outside, graded with a fix for each. Free, no account.

Check your domain

Coprsetr Pro watches up to 5 domains every week and emails you when something slips.

Questions

What does a Content-Security-Policy do?

It tells the browser which places a page may load scripts, styles, images and frames from. If an attacker manages to inject a script tag, the browser refuses to run it because it is not on your list.

Why start in report-only mode?

A strict policy can break a page that loads something you forgot about. Report-only logs what would be blocked and blocks nothing, so you can fix the list first and then enforce it.

Should I use a nonce or a hash?

Use a nonce when your server builds each page, because it can add a fresh random value every time. Use a hash for a fixed inline script that never changes. Either is far safer than allowing all inline scripts.

Does a meta tag work as well as the header?

Mostly, but not completely. A meta tag cannot set frame-ancestors, report-uri or report-only mode, and it only applies after the browser reads it. Send the header when you can.

Keyboard shortcuts

⌘K or /
Search everything
?
This list
g h
Home
g l
Guide library
g f
Find my path
g t
Templates
g p
Playbooks
g w
My workspace
g d
Deadline calendar
g c
Regulatory changes