# CSP and security headers generator

Pick the third-party services your site loads and get a Content Security Policy that allows those and nothing else, plus the other security headers, ready to paste into your server config.

This tool runs entirely in the browser at https://joncphillips.com/tools/csp-generator/. Nothing you type is sent anywhere.

Every time I set up a Content Security Policy, I end up digging through five different vendor docs to find out which domains their scripts load from.

This tool is that list, already put together.

## How to Roll Out a CSP Without Breaking Your Site

**Start with Report-Only.** The browser reports what the policy would have blocked without actually blocking anything. Browse your own site with the developer console open and you'll see what you missed. Once a few days go by without any surprises, switch to the enforcing header.

The service list uses the domains each vendor documents, but vendors add new ones over time, and tag managers load whatever you put in them. If something breaks, the browser console tells you the blocked URL and which rule blocked it, and you can add that domain in the custom fields.

## Inline Scripts and Styles

A strict policy blocks inline `<script>` blocks and attributes like `onclick`. The easiest fix is moving them into files. You can also allow a single inline script by its hash, and the console prints the hash it expected, which is handy.

I'd avoid `'unsafe-inline'` for scripts, since it switches off most of the protection a CSP gives you. Inline styles are a much smaller risk, and that's why the tool lets you allow them with a checkbox.

## The Other Headers

**Strict-Transport-Security** tells browsers to always use https for your domain. Only add `preload` if every subdomain serves https, because getting off the preload list takes months.

**X-Content-Type-Options: nosniff** stops browsers from guessing file types.

**Referrer-Policy** controls how much of your URLs other sites get to see when someone clicks a link.

**Permissions-Policy** turns off browser features you don't use, like the camera and microphone.

## Frequently Asked Questions

### Should I use a meta tag or a header?

A header if you can. The `<meta http-equiv="Content-Security-Policy">` tag works, but it can't set `frame-ancestors` or report-only mode, and it only applies from the point where it appears in the page.

### Does this send my settings anywhere?

Nope. It all runs in your browser.

## Preflight.sh

Preflight checks your codebase for missing security headers along with the rest of the launch checklist, before you deploy. https://preflight.sh/

More free tools: https://joncphillips.com/tools/
