How to Fix Content Security Policy Issues on Your Website
Quick answer: To fix Content Security Policy (CSP) issues, open your browser console and read the error. It tells you what was blocked, where it came from and which directive blocked it. Find where your site sets the policy (server, Cloudflare, a WordPress plugin or a meta tag), switch it to Report-Only while testing, add only that exact domain to the right directive, test every page and form, then enforce it again. Do not fix CSP errors by deleting the policy or allowing everything with a wildcard.
- Fixes without weakening security
- Tracking, forms and payments tested
- Sydney based developer
Key takeaways
A CSP is a security header that tells browsers which sources your site is allowed to load.
Every CSP error names the blocked source and the directive to change, so start in the browser console.
Use Content-Security-Policy-Report-Only to test changes without breaking your live site.
Allow specific domains, not wildcards, and avoid unsafe-eval.
Unknown domains in CSP errors can be a warning sign of malware. Investigate before you allow them.
What is a Content Security Policy?
A Content Security Policy is an HTTP response header that lists the sources your website is allowed to load content from. If a script, style, image, font, iframe or network request comes from somewhere that is not on the list, the browser blocks it. This makes it much harder for attackers to run injected code, such as card skimmers or malicious redirects, on your pages.
CSP is one part of a secure website. Pair it with the basics in the WordPress security checklist.
A policy is made of directives, each covering one type of content:
default-srcFallback for any type not listedYour own domain onlyscript-srcJavaScript files and inline scriptsTag Manager, reCAPTCHA, Stripestyle-srcStylesheets and inline stylesGoogle Fonts CSSimg-srcImages and tracking pixelsAnalytics and ad pixelsfont-srcWeb fontsGoogle Fonts filesconnect-srcRequests made by scripts (fetch, XHR, beacons)GA4 and Meta Pixel dataframe-srcIframes you embedYouTube, Google Maps, payment fieldsframe-ancestorsWhich sites can embed your site in an iframeStops clickjackingWhat do CSP issues look like?
- Google Analytics or Tag Manager suddenly stops recording visits or conversions.
- Contact forms will not submit because reCAPTCHA does not load.
- Embedded YouTube videos or Google Maps show a blank box or a "refused to connect" message.
- Payment fields, live chat or booking widgets do not appear.
- Fonts fall back to a default font, or the layout looks unstyled.
- Your page builder or admin preview stops working.
In the browser console you will see messages such as:
Refused to load the script 'https://www.googletagmanager.com/gtm.js' because it violates the following Content Security Policy directive: "script-src 'self'".
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".
Refused to frame 'https://www.youtube.com/' because it violates the following Content Security Policy directive: "frame-src 'self'".
Refused to connect to 'https://region1.google-analytics.com/g/collect' because it violates the following Content Security Policy directive: "connect-src 'self'".
How to find and read CSP errors
Open the console
In Chrome or Edge press F12 (or Cmd + Option + J on Mac) and open the Console tab. Reload the page and look for red "Refused to..." messages.
Check the header
Open the Network tab, click the first document request and look under Response Headers for content-security-policy.
Scan the whole site
Check other key pages, forms and checkout, because different pages load different tools.

How to read a CSP error in the browser console
Every error gives you four clues: what type of content was blocked, the exact URL, the directive that blocked it, and the sources that directive currently allows. That is all you need to make a precise fix.
How to fix CSP issues step by step
Six steps that fix the error without opening your site up to injected code.
Step 1: Find where your policy is set
Before you change anything, find where the header comes from. Adding a second policy in another place does not loosen the first one, because browsers apply every policy they receive. Common places:
Header set Content-Security-Policy line in .htaccessadd_header Content-Security-Policy in the site confighttp-equiv="Content-Security-Policy"Step 2: Switch to Report-Only while you test
Change the header name to Content-Security-Policy-Report-Only. The browser will log what would be blocked without actually blocking it, so your site keeps working while you adjust the rules.
# Apache (.htaccess)
Header set Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com"
# Nginx
add_header Content-Security-Policy-Report-Only "default-src 'self'; script-src 'self' https://www.googletagmanager.com" always;Step 3: Add only the exact source to the right directive
Copy the domain from the error and add it to the directive named in the message. If a script from https://js.stripe.com was blocked by script-src, add exactly that origin to script-src. Do not add it to default-src or use a wildcard like * or https:, because that lets almost anything run.
Many providers publish the exact domains they need. Google has a CSP guide for Tag Manager and Google tags, and Stripe, Meta and reCAPTCHA have similar documentation.
Step 4: Replace unsafe inline code with nonces or hashes
"Refused to execute inline script" means code is written directly in the page rather than in a file. The quick fix is adding 'unsafe-inline', but that removes much of the protection CSP gives you. Better options:
- Move it to a fileMove the code into a separate .js file on your own domain.
- Use a nonceA random value generated on every page load and added to both the header and the script tag.
- Use a hashA fingerprint of a fixed inline script that you add to
script-src.
On WordPress, inline styles are very common, so many sites allow 'unsafe-inline' in style-src only. That is a reasonable trade-off. Avoid 'unsafe-eval' unless a tool genuinely requires it.
Step 5: Test every page, form and tool
Click through your home page, service pages, blog posts, contact and quote forms, checkout and thank-you pages. Submit a test form, play a video, open a map and check that conversions still appear in Google Analytics. If something is still blocked, repeat step 3 for that error. If tracking stopped while you were testing, see the Google Analytics and Search Console setup guide.
Step 6: Enforce the policy and keep monitoring
When the console is clean, rename the header back to Content-Security-Policy to enforce it. Re-check the console after every new plugin, app, tracking tag or embed, because each one may need a new source. A website maintenance plan makes this part of your regular checks.
Which CSP directives common services need
Use this as a starting point, then copy the exact domains from your console errors and each provider's documentation.

A typical starter policy for a WordPress site using Tag Manager, GA4, Google Fonts, YouTube and reCAPTCHA might look like this:
Content-Security-Policy:
default-src 'self';
script-src 'self' https://www.googletagmanager.com https://www.google.com https://www.gstatic.com;
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
img-src 'self' data: https://www.googletagmanager.com https://*.google-analytics.com;
connect-src 'self' https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com;
frame-src https://www.youtube.com https://www.youtube-nocookie.com https://www.google.com;
frame-ancestors 'self';
base-uri 'self';
form-action 'self';
object-src 'none';
upgrade-insecure-requestsThe header must be sent on one line. It is split here so it is easier to read. If you use the Meta Pixel, follow the Meta Pixel and Conversions API guide and add its domains too.
Fixes for the most common CSP errors
Match the start of your console message to the fix.
script-srcframe-srcconnect-srcstyle-src or font-srcframe-ancestorsupgrade-insecure-requestsIf you see mixed content or certificate warnings, an SSL certificate and HTTPS fix usually solves them.
CSP on WordPress, Shopify and Cloudflare
WordPress
Set the header at the server or Cloudflare where possible, rather than stacking several plugins. Test the admin area separately, because the editor often needs looser rules than the public site.
Shopify
Shopify controls most storefront security headers, so you cannot write your own full policy. CSP errors usually come from apps or custom scripts. Check the console, update or remove the app, or ask its developer.
Cloudflare
A response header transform rule can add or change the CSP for your whole site without touching the server. See Cloudflare setup for CDN and security.
When a CSP error is a warning sign
Not every blocked request is a mistake in your policy. If the console shows scripts from domains you do not recognise, especially on checkout or login pages, your site may have injected code. Do not add those domains to your policy. Read the signs your WordPress site has been hacked and how to remove malware from WordPress, or get help fast with a full site malware cleanup.
CSP mistakes to avoid
- Deleting the policy to make an error go away.
- Using
*,https:ordata:inscript-src. - Adding
'unsafe-inline'and'unsafe-eval'to scripts by default. - Setting the policy in two places that conflict.
- Allowing domains you do not recognise without checking what they are.
- Enforcing a new policy without testing forms, tracking and checkout first.
Need help fixing Content Security Policy issues?
iScreenviewer can find where your policy is set, fix the errors without weakening your security, and check that tracking, forms and payments still work.
Frequently asked questions
What is a Content Security Policy error?
It is a message in your browser console saying a script, style, image, font, frame or connection was blocked because it is not on the list of sources your Content Security Policy allows. The error names the blocked URL and the directive that blocked it.
Can a Content Security Policy break my website?
Yes. A policy that is too strict can stop analytics, forms, maps, videos, payment fields or even your page builder from working. That is why you should test changes in Report-Only mode before enforcing them.
Should I just remove the Content Security Policy?
No. Removing it hides the symptom and leaves your visitors less protected against injected scripts. Fix the policy by allowing only the specific domains and directives your site needs.
Is it safe to use unsafe-inline in my CSP?
It is common on WordPress for styles, but it weakens protection for scripts. Where possible use nonces or hashes for inline scripts instead of unsafe-inline, and avoid unsafe-eval unless a tool truly requires it.
Why does Google Tag Manager break with a Content Security Policy?
Tag Manager loads scripts and sends data to Google domains that your policy may not allow. Add the domains from Google's Tag Manager CSP guide to script-src, img-src and connect-src, then add the domains for any tags it loads.
Can I change the Content Security Policy on Shopify?
Not fully. Shopify manages most security headers on storefronts. CSP problems on Shopify usually come from apps or custom scripts, so check the console error and the app's documentation, or contact the app developer.