A Content Security Policy (CSP) is a rule your site sends to browsers that lists where scripts, styles and images on a page may come from. All else is blocked. It still helps when an attacker has found a way to place a malicious script on your site, because the browser refuses code from a source that is not on the list.
What is a Content Security Policy?
A CSP is a security header that lists which sources of scripts, styles, images and other files a browser may load on a page.
A CSP is sent by your server as a response header, which is why it counts as one of the security headers. The value is a list of rules called directives. default-src sets the fallback for everything, script-src controls where scripts may come from, img-src does the same for images, and so on. Each directive holds the allowed sources, for example your own domain or a named external service.
The browser enforces the rules while it builds the page. That makes a CSP a second line of defense. It does not remove the weakness itself, but it can stop an injected script from running or from sending data to a stranger’s server.
What a CSP means for a PHP or WordPress site
Which PHP version does your site report?
We read only what your site already sends in public: the headers and the top of the homepage. No scan, no login.
The classic problem a CSP helps against is cross-site scripting, where an attacker gets their own script to run in your visitors’ browsers. On a PHP site with many plugins, there are plenty of places where that can go wrong, and a CSP reduces what a successful attempt can do.
The catch is that WordPress is full of inline scripts, inline styles and files loaded from other domains. A strict policy blocks all of that unless you list it, so adding a CSP to an existing site is a project of testing and adjusting. A policy that is too loose gives little protection, and one that is too tight breaks forms, menus or tracking.
A static website is a different starting point. With no PHP and no database running when a page is viewed, the page is a fixed set of files, and you can usually list exactly which sources it needs. That is one of the reasons we offer a WordPress to static site move as an option.
How to try a CSP safely
Browsers support a report-only mode through the Content-Security-Policy-Report-Only header. In that mode nothing is blocked, but the browser logs what the policy would have blocked. You can read those messages in the developer console.
A sensible order looks like this:
- Check your current headers to see whether a CSP exists already.
- Add a draft policy in report-only mode.
- Browse your own site, including forms and checkout, and note every warning.
- Add the sources you trust, remove the ones you do not need and repeat.
- Switch to the enforcing header once the console stays quiet.
Test on a copy of the site, not on the live one, so a mistake does not reach visitors.
When to act
A CSP is worth adding when your site handles logins, payments or personal data, or when you have already had a script injected. It is not a substitute for updates: if the site runs on a version of PHP that no longer gets security fixes, the first step is moving to a supported release. A CSP is the layer you add after that.
Not sure how this applies to your site?
Ask a person to take a look. We check which PHP version your site runs and whether the fix is in, and tell you the next step.
Or have PHP updated right away: PHP update from $555 excl. VAT
Frequently asked questions
Does a Content Security Policy stop all attacks?
No. A CSP limits what a browser will run or load, which reduces the damage of attacks such as cross-site scripting. It does not fix a vulnerable plugin or an outdated PHP version, so it works next to updates, not instead of them.
Why did my site break after I added a CSP?
A strict policy blocks anything it does not list, including inline scripts and third-party tools such as analytics or chat widgets. Start in report-only mode, read what would have been blocked and then add the sources you actually trust.
Is a CSP hard to set up on WordPress?
Often, yes. Themes and plugins add inline scripts and load files from many places, so a strict policy takes careful testing. A static site usually has far fewer moving parts, which makes a tight policy easier to keep.