CSP Builder

Build a Content-Security-Policy from a strict, balanced or lockdown preset plus your own allowed sources. It prints the header, a meta tag, an nginx line and an Apache line.

Use the tool

Why this tool exists

A Content-Security-Policy is one of the strongest defences against cross-site scripting, but writing one from scratch is fiddly. A single wrong source breaks scripts or fonts, and a policy that is too loose gives a false sense of security.

This builder starts from a preset: strict with nonces and strict-dynamic, balanced with same-origin defaults, or lockdown with everything denied. You add the hosts you really need for scripts, styles, images, fonts, connections, frames and media, set frame-ancestors and an optional report address, and choose whether to send it as Report-Only. The output is ready to paste into server config. Test in report-only mode first, because the tool cannot know what your pages load.

How to use it

  1. Choose a preset: strict, balanced or lockdown.
  2. Add extra sources for script, style, image, font, connect, frame and media directives, separated by spaces.
  3. Set frame-ancestors and a report URL if you have one, and tick Report-Only to test first.
  4. Run the tool and copy the header, meta tag, nginx or Apache line.

Frequently asked questions

Which preset should I start with?

Balanced is the simplest to adopt. Strict gives better protection against injected scripts but needs a fresh nonce on every response. Lockdown denies everything by default and suits static sites.

Why should I use Report-Only first?

Report-Only logs violations without blocking anything, so you can find sources you forgot before enforcing the policy. Switch it off only when reports are clean.

What are the limits of the meta tag version?

Meta tags ignore frame-ancestors, report-uri and sandbox, and do not support Report-Only. Use the HTTP header where you can.

Does it upload my settings?

No. The policy is built in your browser from the options you choose and nothing is sent anywhere.