Skip to content

PHP security updates released 21 October 2026. The flaws are now being actively exploited, so check your website's PHP is up to date. Patches are available for older PHP versions too. What it means for your website

Content Security Policy

Content Security Policy (CSP) explained

A Content Security Policy tells browsers which sources of scripts and other content your website trusts. It's one of the strongest browser protections available, and the easiest to get wrong.
Published 4 November 2026 · Last updated 4 November 2026 · By Host Dada

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-src is 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-src controls JavaScript, and it's the rule that matters most.
  • style-src, img-src and connect-src cover stylesheets, images and the connections scripts can make.
  • object-src 'none' blocks old-style plugin content, which almost no modern site needs.
  • base-uri and form-action limit where relative links can point and where forms can send data.
  • frame-ancestors controls 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' in script-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' in script-src. This allows scripts to turn text into running code.
  • Wildcards and whole schemes, such as * or https: in script-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

  1. 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.
  2. 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.
  3. 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.
  4. Enforce it. Once reports show only things you meant to block, change the header name to Content-Security-Policy.
  5. 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.

Check My Website — Free