CSP generator

A Content-Security-Policy stops injected scripts running, but a copied policy breaks analytics, payments and chat widgets. This scans what a page actually loads, adds the extra hosts common services need behind the scenes, and builds a report-only policy. Then it collects the browser's violation reports live, so you can see what it would block before you enforce it.

How to roll out a CSP without breaking the site

  1. Build it from the real page. Scan the pages that load the most third-party code: the homepage, a product page, the basket and checkout, and anything with a form or map.
  2. Deploy it as Report-Only. The browser checks every request against the policy and reports what it would have blocked, but blocks nothing. Visitors see no difference.
  3. Watch the reports for a few days. Tag Manager in particular loads things that never appear in the HTML. Add the legitimate hosts and ignore the noise (browser extensions inject plenty).
  4. Switch to enforcing. Change the header name to Content-Security-Policy, keep the report-uri so you hear about anything new, and test checkout and forms straight away.

Why inline scripts are the hard part

Most of a CSP's protection comes from refusing to run scripts that weren't put there on purpose. Allowing 'unsafe-inline' for scripts throws much of that away, because injected code is usually inline. The proper fix is a nonce: a random value the server adds to each script tag and to the header on every request, so only scripts carrying it run. WordPress doesn't do this out of the box, which is why many WordPress policies start with 'unsafe-inline' and still get value from restricting where external scripts, frames and forms can go.

Questions agencies ask

An HTTP header that tells the browser which sources a page is allowed to load scripts, styles, images, fonts and frames from. If an attacker manages to inject a script, the browser refuses to run it because its source isn't on the list. It's one of the strongest defences against cross-site scripting.

FOR AGENCIES

Need a CSP that doesn't break checkout?

I set up Content-Security-Policy and the other security headers for agencies, including nonces in Laravel and WordPress, policies that work with Tag Manager and payment providers, and the monitoring that catches problems first.

  • White-label, under your brand, or alongside your team
  • Laravel, WordPress, WooCommerce, integrations and tracking
  • Inherited and half-finished sites taken over and stabilised
  • UK based, straight to the developer, no account managers

Related free tools