Content-Security-Policy (CSP) check
A Content-Security-Policy header tells the browser which scripts, styles and other resources your pages may load. It's the main browser-side defence against cross-site scripting (XSS) and card-skimming scripts. SiteShield fails a site with no CSP, warns on report-only or 'unsafe-inline' policies, and passes an enforced policy. Roll it out in Report-Only mode first.
What is Content-Security-Policy?
A CSP is a list of directives, each with an allow-list. default-src 'self' means "only load from my own origin unless another directive says otherwise"; script-src controls JavaScript; frame-ancestors controls who may frame your page. Browsers block anything the policy doesn't allow and can report violations to you.
Content-Security-Policy: script-src 'self' 'unsafe-inline' https:Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'Why it matters
A CSP limits which scripts can run on your pages. It is the main defence against cross-site scripting and card-skimming scripts (Magecart).
If an attacker manages to inject a script tag (through a vulnerable plugin, a comment field or a compromised third-party script), a good CSP stops the browser from running it or from sending stolen data to the attacker's server. Online shops are the main target: "Magecart" skimmers add a few lines of JavaScript to the checkout page and copy every card number typed in. PCI DSS 4.0 requirement 6.4.3 asks merchants to control and authorise every script on payment pages, and a CSP is the usual way to enforce that.
SiteShield maps this check to:
See how these standards fit together in the UAE website security checklist.
How SiteShield grades it
This check, "Content-Security-Policy", can cost up to 10 points: a fail loses all 10, a warning loses 5. Every scan starts at 100.
| Result | When | Points lost |
|---|---|---|
| Fail | No Content-Security-Policy header (and no report-only header). | 10 |
| Warning | Only Content-Security-Policy-Report-Only is sent, so nothing is actually blocked yet. | 5 |
| Warning | An enforced policy whose script-src (or default-src if there's no script-src) allows 'unsafe-inline' without a nonce, hash or 'strict-dynamic'. | 5 |
| Pass | An enforced policy without unrestricted inline scripts. | 0 |
How to check it yourself
Read the header, then open your browser's developer tools (Console tab) to see what it blocks:
curl -sI https://example.com | grep -i content-security-policy
Or run a free SiteShield scan, which checks this and 16 other settings in one go.
How to fix it
The quick version: Start with a report-only policy, e.g. Content-Security-Policy-Report-Only: default-src 'self'; then allow the domains you really use and switch to enforcing.
Any platform: roll it out safely
- Start with
Content-Security-Policy-Report-Onlyand the strict policy you want. Browsers log what would be blocked without breaking anything. - Browse every page type for a week or two and add the domains you really use (analytics, fonts, payment widgets) to the right directive.
- Replace inline scripts with files, or give them a nonce or hash.
- Rename the header to
Content-Security-Policyto enforce it. Keep a report-only copy of a stricter policy if you want to tighten further.
Cloudflare
Go to Rules → Transform Rules → Modify Response Header, create a rule for your hostname, choose Set static, header name Content-Security-Policy-Report-Only (later Content-Security-Policy) and paste your policy as the value.
Nginx
In the server block (one line):
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'" always;Apache
With mod_headers enabled:
Header always set Content-Security-Policy "default-src 'self'; script-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'self'"WordPress
- WordPress themes and plugins print a lot of inline JavaScript, so a strict policy usually breaks something at first. Start report-only, set it at the server or CDN, and test the front end, the checkout and wp-admin separately.
- If you run WooCommerce, give the checkout page the tightest policy you can (PCI DSS 6.4.3).
FAQ
Why is 'unsafe-inline' a problem?
Most XSS attacks inject inline script. Allowing 'unsafe-inline' in script-src lets that injected script run, which removes most of the protection. Use nonces or hashes instead; browsers ignore 'unsafe-inline' when a nonce or hash is present.
Does a report-only CSP count?
It's a good first step, so SiteShield gives it a warning rather than a fail, but it doesn't block anything. Switch to the enforcing header once the reports are clean.
Does CSP replace fixing XSS bugs?
No. CSP is a second line of defence. You still need to escape output and validate input, but CSP limits the damage if a bug slips through.
Is CSP required for PCI DSS?
PCI DSS 4.0 requirement 6.4.3 requires that scripts on payment pages are authorised, their integrity is assured and an inventory is kept. It doesn't name CSP, but a CSP is the most common technical control used to meet it.
Test your Content-Security-Policy now
Run all 17 checks on your website and email domain in about 30 seconds. Free, no signup, passive checks only.
Rather not do it yourself? Fix it for me starts at AED 750 (about USD 205 by PayPal), quote agreed first. Monitoring re-scans weekly for AED 99/month or AED 990/year.