Content Security Policy
Content Security Policy (CSP) explained
What a Content Security Policy does
Normally, a browser runs any script that appears in a page. So if an attacker manages to inject a script through a vulnerable form, plugin or third-party widget, it runs as if your website had written it, and it can read what visitors type or send them elsewhere. This is known as cross-site scripting (XSS).
A Content Security Policy is an instruction, usually sent as an HTTP header, listing what the page may load and run. Anything not on the list is refused. The policy doesn't remove the original flaw, which still needs fixing. Its job is to limit what an attacker can do with it.
How to read a policy
A policy is a list of rules, called directives, separated by semicolons. Here's a strict one, close to what this website uses:
Content-Security-Policy:
default-src 'self';
script-src 'self';
style-src 'self';
img-src 'self' data:;
connect-src 'self';
object-src 'none';
base-uri 'self';
form-action 'self';
frame-ancestors 'none'default-srcis the fallback for most resource types that don't have their own rule.'self'means your own site's origin: the same scheme, host and port.script-srccontrols JavaScript, and it's the rule that matters most.style-src,img-srcandconnect-srccover stylesheets, images and the connections scripts can make.object-src 'none'blocks old-style plugin content, which almost no modern site needs.base-uriandform-actionlimit where relative links can point and where forms can send data.frame-ancestorscontrols which sites may embed your pages, which protects against clickjacking.
One detail catches people out: base-uri, form-action and frame-ancestors don't fall back to default-src. If you want them restricted, you have to set them yourself.
What makes a policy weak
'unsafe-inline'inscript-src. This allows scripts written directly into the page, which is the form injected code usually takes. It removes much of the protection against XSS.'unsafe-eval'inscript-src. This allows scripts to turn text into running code.- Wildcards and whole schemes, such as
*orhttps:inscript-src. These allow scripts from almost anywhere. - Very broad hosts. If you allow a large shared content host, an attacker may be able to load their own script from it.
If your site really does need inline scripts, a nonce (a random value generated for each response) or a hash of the script lets you approve those specific scripts without using 'unsafe-inline'.
Why it's hard on WordPress and busy sites
A policy has to list everything your site legitimately uses. On a simple custom site, that may be a short list. On a typical WordPress site, the themes and plugins often write inline scripts and styles, and analytics, tag managers, chat widgets, video embeds and payment forms each bring their own hosts. If you miss one, that feature quietly stops working for visitors. Adding a new plugin or marketing tag can break things months later.
That's why we treat a missing policy as a longer-term improvement and not something to rush. It's worth having, but only if someone will look after it.
How to roll one out safely
- List what your site loads. Browser developer tools show every request a page makes. Check your important journeys, not just the home page: contact forms, checkout, logins and anything with an embed.
- Start in report-only mode. Send your draft as
Content-Security-Policy-Report-Only. Browsers then report what would have been blocked, in the developer console and to a reporting address if you set one, while blocking nothing. - Adjust and wait. Leave it running long enough to catch less common pages and traffic. Expect some noise, as browser extensions can trigger reports too.
- Enforce it. Once reports show only things you meant to block, change the header name to
Content-Security-Policy. - Keep looking after it. Make the policy part of adding any new plugin, widget or tag.
What our checker reports
The check looks for a policy in the headers of your home page response:
- Enforced policy found: reported as set, with the header shown as evidence. We don't score its contents, so use the list of weaknesses above to review it yourself.
- Report-only policy found: flagged for attention, because it isn't enforced yet.
- No policy found: flagged for attention, as a configuration recommendation. It isn't a sign your site has been compromised.
A frame-ancestors rule in an enforced policy also counts as clickjacking protection. A policy set with an HTML <meta> tag won't be picked up, as we only read the header. A meta tag also can't apply some rules, including frame-ancestors, so the header is the better choice anyway.
CSP is one of several headers we look at. Our security headers guide covers the others, and version leaks are a much smaller fix if you want a quick win.
Run the free check
Check your website now. It's free, needs no account and takes a few seconds. You can read exactly how the check works and what it can't see, or find out more about the Security Checker on hostdada.co.uk.
Check your website now
Free, passive and takes a few seconds. No account needed.
Guides for website owners
- PHP security warning (October 2026)What the critical PHP fixes mean for your website.Read guide
- Check your PHP versionIs your PHP version supported? Check it against official data.Read guide
- Find your PHP version in WordPressStep-by-step, with or without dashboard access.Read guide
- WordPress security checkerWhat we can (and can't) see about WordPress sites.Read guide
- How the check worksEvery check explained, plus its limitations.Read guide
- Security headers explainedWhat each header does and how we judge it.Read guide
- HSTS explainedWhat a redirect can't do, and how to enable HSTS safely.Read guide
- SSL certificate checkValidity, expiry and what certificate errors mean.Read guide
- X-Powered-By and version leaksWhat your site gives away, and how to remove it.Read guide
- Website hacked? What to checkThe signs, the first hour and a proper clean-up.Read guide