A missing Content-Security-Policy header means the browser will execute any script that ends up in your pages, including one injected through a compromised plugin, a hijacked ad tag or a cross-site scripting flaw. You fix it by adding the Content-Security-Policy response header at the web server, CDN or application layer. The safe way to do that is to ship the policy in report-only mode first, read the violation reports for a week or two, then switch to enforcing once the reports are clean.
Why this matters for your website
CSP is the only control that limits the damage after something malicious reaches the page. Patching stops known holes; CSP contains the unknown ones. On a WooCommerce checkout or a SaaS billing page, that difference is the difference between a blocked script and stolen card data.
There is a business reason too. Card-data environments and enterprise security questionnaires increasingly ask which script sources your payment pages allow. A missing header is an easy finding for any scanner and an easy question to fail.
What a Content-Security-Policy header actually does
CSP is a response header that tells the browser which origins are allowed to load each type of resource: scripts, styles, images, fonts, frames and network connections. Anything outside the allowlist is blocked before it runs, and the browser can report the block to an endpoint you choose. Directives such as script-src control code execution, frame-ancestors controls who may embed your site in an iframe, and upgrade-insecure-requests rewrites stray HTTP subresources to HTTPS. The full directive reference is on MDN, and OWASP maintains a CSP cheat sheet with recommended baselines.
The safe rollout, step by step
Work through these five steps in order. Skipping straight to an enforcing policy is what breaks sites.
1. Inventory what your pages load
Open your busiest templates (home, product, cart, checkout, login) in a browser and read the Network tab. Write down every third-party host you see, grouped by type: scripts, stylesheets, fonts, images, iframes and XHR/fetch endpoints. Include tag managers, chat widgets, review platforms, A/B testing tools and payment iframes.
2. Deploy in report-only mode
Send Content-Security-Policy-Report-Only instead of Content-Security-Policy. The browser evaluates the policy, blocks nothing, and posts a JSON report to the endpoint in your report-uri or report-to directive. Run it for at least one full traffic cycle, including a weekend and any scheduled campaign, so you catch scripts that only load on certain pages.
3. Build the policy directive by directive
Start from default-src 'self' and open up only what the reports prove you need.
default-src 'self'— the fallback for anything not named explicitly.script-src— your own origin plus a nonce or hash per inline script; avoid'unsafe-inline'.style-src— your origin plus font/CSS CDNs you actually use.img-src 'self' data: https:— a pragmatic starting point for image-heavy catalogues.font-src— your origin and any webfont host.connect-src— analytics collectors, APIs and websocket endpoints.frame-ancestors 'none'— stops clickjacking; use'self'if you embed your own pages.object-src 'none'andbase-uri 'self'— cheap wins that close common bypasses.upgrade-insecure-requests— rewrites leftover HTTP subresources.
Paste each draft into the Google CSP Evaluator before you ship it. It flags allowlists that are effectively bypassable and pushes you toward nonce-based policies.
4. Handle the usual blockers
- Google Tag Manager and Analytics — allow
https://www.googletagmanager.cominscript-srcandhttps://*.google-analytics.cominconnect-srcandimg-src. GTM can inject inline code, so pass your nonce to the container snippet. - Embedded YouTube — add
https://www.youtube-nocookie.com(orhttps://www.youtube.com) toframe-src. - Stripe — add
https://js.stripe.comtoscript-srcandframe-src, andhttps://api.stripe.comtoconnect-src. - Inline WordPress scripts — themes and plugins print inline
<script>blocks. Either add a nonce via your server or templates, or hash the small, static ones withsha256-. - Admin screens — exclude
/wp-adminfrom enforcement until you have tested it; block editors rely heavily on inline code.
5. Switch to enforcing
When reports show only noise from browser extensions, rename the header from Content-Security-Policy-Report-Only to Content-Security-Policy. Keep the reporting endpoint switched on after the cutover. Deploy to a staging host or a single template first, and keep a one-line rollback ready.
Copy-paste configurations
Set the header at the server or CDN so it applies to every response, including static files and error pages.
# nginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com; connect-src 'self' https://*.google-analytics.com; img-src 'self' data: https:; style-src 'self'; font-src 'self'; frame-ancestors 'none'; base-uri 'self'; object-src 'none'; upgrade-insecure-requests; report-uri /csp-report" always;# Apache (mod_headers)
Header always set Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com; connect-src 'self' https://*.google-analytics.com; img-src 'self' data: https:; frame-ancestors 'none'; base-uri 'self'; object-src 'none'; upgrade-insecure-requests; report-uri /csp-report"On Cloudflare, go to Rules, then Transform Rules, then Modify Response Header. Create a rule that matches all hostnames, choose Set static, enter the header name and the policy string as the value. Cloudflare applies it on top of whatever your origin sends, so remove any duplicate header at the origin.
On WordPress, server level is preferred. If you have no server access, a headers plugin or a small snippet on the send_headers hook works, but it will not cover static assets served directly by the web server. Test with a logged-out browser session and with the admin bar visible.
How to check your own site
First, confirm what you send today. The free check your headers free tool shows whether a CSP header is present at all, alongside HSTS, X-Content-Type-Options, Referrer-Policy and Permissions-Policy. If you want the wider context first, read security headers explained.
Scantinel (scantinel.ai) is an automated website security assessment platform that runs OSINT, network and OWASP Top 10 web vulnerability tests against ownership-verified assets and delivers actionable, business-owner-legible reports. The Essential scan goes further than a header presence check: it flags weak directives such as unsafe-inline and overly broad wildcards, and reviews cookie flags, TLS configuration and known-vulnerable CMS plugins in the same pass. A scan is not a penetration test; it is an automated assessment that tells you what to fix first. Plan details are on the pricing page.
Key takeaways
- A missing Content-Security-Policy header leaves the browser willing to run any injected script on your pages.
- Always start with
Content-Security-Policy-Report-Onlyand a reporting endpoint; never enforce on day one. - Build from
default-src 'self'and add only the hosts your violation reports prove you need. - Prefer nonces or hashes over
'unsafe-inline', and validate every draft in the Google CSP Evaluator. - Set the header at the server or CDN layer so it covers static assets and error pages too.
Frequently asked questions
Will a content security policy break my website?
It can, if you enforce a strict policy before testing it. Report-only mode removes that risk entirely: the browser reports what would have been blocked and changes nothing for visitors. Only switch to the enforcing header once the reports are quiet.
What is the safest starting CSP?
A good baseline is default-src 'self'; object-src 'none'; base-uri 'self'; frame-ancestors 'none', sent as report-only. It blocks the highest-value attack paths while you collect data on legitimate third parties. Add script-src, connect-src and frame-src entries as the reports reveal them.
Do I need CSP if I have HTTPS?
Yes. HTTPS protects data in transit; it says nothing about which code runs in the page. A malicious script loaded from a compromised plugin or third-party tag is delivered over your valid TLS connection just like everything else, and only CSP can stop it from executing.
Published January 2026 by the Scantinel Security Research Team. Verify current guidance against primary sources such as OWASP, NVD and WPScan before you act.
Comments
No comments yet.