How to Fix Content Security Policy Issues on Your Website

How to Fix Content Security Policy Issues on Your Website
Hosting & Security10 min readUpdated 26 Nov 2026

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
The short version

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.

The basics

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 only
script-srcJavaScript files and inline scriptsTag Manager, reCAPTCHA, Stripe
style-srcStylesheets and inline stylesGoogle Fonts CSS
img-srcImages and tracking pixelsAnalytics and ad pixels
font-srcWeb fontsGoogle Fonts files
connect-srcRequests made by scripts (fetch, XHR, beacons)GA4 and Meta Pixel data
frame-srcIframes you embedYouTube, Google Maps, payment fields
frame-ancestorsWhich sites can embed your site in an iframeStops clickjacking
Spot the signs

What 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:

Console · 4 errors

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'".

Diagnose first

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.

Review the policy

Paste it into Google's CSP Evaluator to spot weak or risky settings.

DevTools · Console
Annotated Content Security Policy console error showing what was blocked, where it came from, which directive blocked it and what is currently allowed
How to read a CSP error in the browser console

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.

Clue 1Content type blocked
Clue 2The exact URL
Clue 3The directive
Clue 4What it allows now
The fix

How to fix CSP issues step by step

Six steps that fix the error without opening your site up to injected code.

1

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:

Web server (Apache)Look for a Header set Content-Security-Policy line in .htaccess
Web server (Nginx)Look for add_header Content-Security-Policy in the site config
CloudflareCheck Rules for response header transform rules
WordPressSecurity or headers plugins, or code in the theme functions.php
Meta tagView source and search for http-equiv="Content-Security-Policy"
Hosting panelSome hosts add security headers in their dashboard
2

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;
3

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.

4

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.

5

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.

6

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.

Cheat sheet

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.

CSP cheat sheet
CSP cheat sheet table matching Google Tag Manager, GA4, Meta Pixel, YouTube, Google Maps, reCAPTCHA, Google Fonts, Stripe and Microsoft Clarity to the directives they need
Common services and the CSP directives they need

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-requests

The 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.

Error lookup

Fixes for the most common CSP errors

Match the start of your console message to the fix.

Refused to load the scriptAn external JavaScript file is not allowed
Add its origin to script-src
Refused to execute inline scriptCode inside the page is blocked
Move it to a file, or use a nonce or hash
Refused to frameAn iframe embed is blocked
Add the embed origin to frame-src
Refused to connect toA script cannot send or fetch data
Add the endpoint to connect-src
Refused to load the stylesheet or fontCSS or font files are blocked
Update style-src or font-src
Refused to display in a frame because an ancestor violates frame-ancestorsAnother site (or your builder preview) cannot embed your page
Add the trusted origin to frame-ancestors
Mixed content warningsHTTP files on an HTTPS page
Update the URLs to HTTPS or add upgrade-insecure-requests

If you see mixed content or certificate warnings, an SSL certificate and HTTPS fix usually solves them.

By platform

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.

Avoid these

CSP mistakes to avoid

  • Deleting the policy to make an error go away.
  • Using *, https: or data: in script-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.
Let me fix it

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.

FAQs

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.

MS

Last updated 26 November 2026. Written by Mark Serdina, web developer at iScreenviewer, based on hands-on security fixes for client websites and documentation from MDN Web Docs, web.dev and Google.

Back to blog
Get in touch

Have a project in mind?

Tell me about your idea. I'll get back to you with honest advice and a clear quote.

  • Talk directly to the developer
  • Clear quotes before any work starts
  • Sydney CBD based
Contact us