The Content-Security-Policy does not stop injected scripts
A CSP is sent, but it allows inline scripts, eval or any host, or only reports, so it would not block an attack.
Why it matters #
A policy that allows 'unsafe-inline' or 'unsafe-eval' in script-src, or any host with *, lets an injected script run just as if there were no policy. In report-only mode the browser blocks nothing at all; it only reports.
Report-only is the right way to test a new policy, so that finding is a reminder to finish the job rather than a fault.
How to fix it #
Move inline scripts into files, or give them a nonce or hash, then remove 'unsafe-inline' and 'unsafe-eval' from script-src and list only the hosts you use. When the reports show nothing you need is blocked, send the policy as Content-Security-Policy.
Change one rule at a time and test the pages that matter most, such as checkout and forms. The Security Headers Checker shows each rule.
What it looks like, and fixed #
Content-Security-Policy: default-src *; script-src * 'unsafe-inline' 'unsafe-eval'
Any host, inline scripts and eval are all allowed, so an injected script runs as if there were no policy.
Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-R4nd0mValuePerPage' https://www.googletagmanager.com; object-src 'none'; base-uri 'self'
Inline scripts carry the matching nonce attribute. The nonce must be a new random value on every page load, never a fixed word.
Fix it with your AI assistant #
Paste this into ChatGPT, Claude, Gemini or your coding agent. Fill in the words in [square brackets] first. It checks before it changes anything, changes only this, and tells you how to prove it worked.
Help me tighten the Content-Security-Policy on [your website address], built with [your platform, e.g. WordPress with WooCommerce]. A checker says my CSP would not stop injected scripts: it allows 'unsafe-inline', 'unsafe-eval', any host with *, or runs in report-only mode. First check: run "curl -sI https://[your domain]/" (or ask me to paste the headers) and read my current policy, then read the source of my key pages and list the inline scripts and outside hosts they use. Explain plainly which rules make the policy weak. Then give me a step-by-step plan: move inline scripts into files or give them a nonce or hash, list only the hosts I use, then remove 'unsafe-inline' and 'unsafe-eval' from script-src. Rules: one change at a time, test in report-only mode first, never break checkout, payments or forms, back up first, and keep all other headers. Give the exact new header and any code changes, and where they go. Finally, tell me to re-check with the URSY.com Security Headers Checker at ursy.com/security-headers-checker/.
We find the problems, and help you fix them
- Check Run a free tool or the full audit.
- Fix it with your AI Download your AI Fix Pack and drop it into ChatGPT, Claude or Gemini. A free account is enough.
- Re-check Come back, check again, and watch each fix turn green.
Fix it on your platform #
WordPress #
WordPress and many plugins print inline scripts, so a strict policy usually needs nonces added by a plugin or custom code. Work on a staging copy and test checkout and the editor.
Your server or hosting #
Change one rule at a time in the header, watch the reports, and only then send the policy as Content-Security-Policy.
Check it is fixed #
Run the Security Headers Checker again: script-src should no longer allow 'unsafe-inline', 'unsafe-eval' or *, and the policy should be enforced, not report-only.
Official source #
web.dev: Mitigate cross-site scripting (XSS) with a strict Content Security Policy
Questions #
Is report-only mode wrong? #
No, it is the right way to test. It just blocks nothing, so plan to switch to the enforced header once the reports are clean.
What is a nonce? #
A random value the server puts in the header and on each inline script it trusts. The browser runs only the inline scripts that carry the matching value.
More problems in Security and HTTPS
- A form sends its data over plain http High priority
- Hidden instructions aimed at AI assistants High priority
- http:// does not redirect to https:// High priority
- Mixed content: files loaded over plain http High priority
- The certificate does not cover this address High priority
- The certificate has expired or is not valid yet High priority
- The certificate is not trusted by browsers High priority
- The https page redirects back to http High priority