How to roll out a CSP without breaking the site
- 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.
- 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.
- 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).
- 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.
The Content-Security-Policy-Report-Only header applies the same rules but blocks nothing. The browser just reports what it would have blocked to the report-uri. It's how you test a policy on a live site without breaking it, which is why this generator starts there.
Because they load and send data to hosts that never appear in the page's HTML: region-specific analytics endpoints, ad pixels, and anything added inside the Tag Manager container. The generator adds the known ones for common services, and the live reports catch the rest.
Yes, usually with 'unsafe-inline' for scripts to start with, because WordPress and its plugins print inline scripts without nonces. Even then the policy controls where external scripts, frames and form submissions can go, which still blocks a lot of attacks. Add it with .htaccess, the server config or a security headers plugin.
A random value generated fresh on every page load, added to the CSP header and to each legitimate script tag. Only scripts with the matching nonce run, so injected inline scripts are blocked. Laravel supports this with Vite::useCspNonce(), and adamdawson.uk itself uses it.
Each collector lasts 24 hours and keeps up to 100 reports. Reports are only visible to people with the collector address, and are deleted when it expires.
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