How to Fix Magento Content Security Policy Errors That Block Tracking on Checkout

|Dan Giura
How to Fix Magento Content Security Policy Errors That Block Tracking on Checkout

TL;DR

The browser's console line tells you which of three routes applies: allow a host, allow an inline script by hash or nonce, or add a Google domain. The GA4 PRO extension already adds the hosts of the integrations you've switched on. What it can't know is your tagging server or a script you pasted in yourself, and its Additional CSP Hosts field covers two directives only. Keep the checkout in restrict mode while you fix it.

Key Takeaways

  • Read the directive in the console line first; it decides the route [4].
  • A blocked host goes into a custom module's csp_whitelist.xml, under the directive that was named [2].
  • An inline script from a GTM Custom HTML tag or the Design Configuration needs a hash, or a nonce for GTM [3].
  • A nonce avoids the hash upkeep, and it also lets anyone who controls your GTM account run scripts on checkout [3].
  • PRO's Additional CSP Hosts field (1.17.6) writes to img-src and connect-src only [8].
  • Google lists a tagging server under img-src, connect-src and frame-src [5], so a subdomain server usually needs a developer too.
  • Don't fix a blocked tag by moving the checkout to report-only.

Which part of your Magento CSP blocked the tag, and who can fix it?

Open the browser console on the checkout step and find the line for the blocked tag. For an inline script, Adobe's documented message begins "Refused to execute inline script because it violates the following Content Security Policy directive" and then names the directive, for example script-src [4]. Google's Tag Assistant also lists the resources your policy blocks [5]. Telling a CSP block from an ad blocker is a different job; ad blockers and browser privacy covers it, and this article starts once you know it's the policy.

Adobe also says why this is developer work: CSP is configured from the server, not from the Admin, so most merchants need a system integrator or developer [1]. The one Admin-side exception here is the PRO field described below.

What the console or Tag Assistant shows Route Who does it
A host refused under img-src or connect-src (a Google country domain, say) Additional CSP Hosts, PRO 1.17.6 or later; or the module file Admin user (PRO) or developer
A host refused under script-src or frame-src Module csp_whitelist.xml entry for that directive Developer
"Refused to execute inline script", from a GTM Custom HTML tag Hash in the module file, or sign the tag with a nonce Developer, plus whoever owns GTM
The same message, from code pasted into the Design Configuration Hash in the module file Developer
A tagging server on a subdomain Google lists img-src, connect-src and frame-src Developer for any directive the field doesn't cover
A GTM Custom JavaScript variable that returns undefined A different case; see the eval note in the inline-script section Developer

What does the GA4 extension already allow, and what does it leave to you?

In the PRO extension, the policy is built from your settings. Since version 1.17.1 (July 7, 2026), the hosts for the integrations you've switched on are added to your policy while the integration is switched on, which the change log describes as "the narrowest possible policy out of the box, with no manual whitelisting required for the enabled integrations" [8]. The guide marks dynamic whitelisting and the Additional CSP Hosts field as PRO features [8]. Pixel setup from one admin covers what each pixel adds. Which Magento release added which Analytics host is in the 2026 patch-reality guide, so it isn't repeated here.

The field itself arrived in 1.17.6 (October 29, 2026), under General Configuration. Its admin text reads: "Hosts added to the img-src and connect-src directives of the store's Content Security Policy, one per line. Use it for Google's country domains when Google Ads or the conversion linker run on your store, for example *.google.de or *.google.co.uk. Only host names are accepted, optionally with a *. prefix." [8]

Read that text for its limits. It reaches two directives. It can't allow a new script host, and it can't allow a frame host. For those you need the module file in the next section. The change log says First-Party Tracking now works on strict-policy pages such as the Magento checkout and Hyvä CSP [8]; first-party tracking with the generated Cloudflare worker covers the setup. PRO also includes a separate compatibility module for the Hyvä CSP theme [8], and GA4 and the Hyvä theme covers Hyvä setup.

Allow a new host for a tag you added

Say you added a tag that loads from a host the extension doesn't know. Adobe's developer guide describes the fix: "You can add a domain to the whitelist for a policy (like script-src, style-src, font-src and others) by adding a csp_whitelist.xml to your custom module's etc folder" [2]. A developer creates a policy entry for the directive, with a value entry of type host.

Pick the directive the console line named. Adobe's own example of what to avoid: "adding a domain to a default-src policy when you only need to load a .js file from it is not recommended. Add the domain to script-src instead" [2]. It also tells you to add resources only in the modules that require them [2]. After the change, Adobe's KB steps end with a cache flush, from System > Tools > Cache Management or with bin/magento cache:flush [3].

How do you allow an inline script from a GTM Custom HTML tag or the Design Configuration?

Two cases come up often, and Adobe's knowledge base names both. The JavaScript from a GTM Custom HTML tag "is injected into the storefront by Google Tag Manager itself", so it isn't pre-whitelisted and gets blocked. And JavaScript added to Scripts and Style Sheets in the HTML Head, or Miscellaneous HTML in the Footer, of the Design Configuration "must be manually whitelisted to be executed on the checkout page" [3]. The developer guide says the same of anything you add in the Admin: you whitelist the content of the script and style tags [2]. This KB covers Adobe Commerce on cloud infrastructure and on-premises, so check your edition [3].

The hash route: a developer takes a sha256 hash of the tag's content, encodes it as BASE64 and adds it to the module's csp_whitelist.xml [2]. The easy way to get the right string is the console error itself: its last sentence carries the generated hash for the blocked script, and Adobe says to use the hash Chrome generates [3].

The catch with GTM is fragility. GTM may modify the JavaScript before injecting it, "including removing line breaks and comments", and Google's processing may change without notice, which can invalidate the hash. Plan to update it periodically [3].

The nonce route is the one Adobe's KB suggests for GTM Custom HTML when hashes keep breaking [3]. It comes with a warning from the same page: if your GTM account is compromised, an attacker can inject JavaScript and sign it with the nonce, "allowing its execution", which "could potentially lead to the theft of sensitive data during the checkout process" [3]. So the choice between a hash and a nonce is a question about who can publish in your GTM container. If that's a long list, take the hash and the maintenance that goes with it.

One separate case. Google's CSP guide says Custom JavaScript variables "evaluate to undefined" under a policy unless unsafe-eval is in script-src, and also says the use of unsafe-inline "is discouraged" [5]. Adobe's page notes that eval() is still allowed in its policy [2]. If a variable fails, compare your live policy with that note before changing anything.

For how the container snippet itself keeps its nonce, adding Google Tag Manager to Magento 2 has the details.

Add your tagging server or a country Google domain

The extension doesn't set your server container URL. You add it to the web Google tag yourself, so the policy can't learn it from the extension; connecting Magento to a GTM server container covers that step. Google's CSP guide says that when the Google tag sends data to a server container, "the CSP must also allow your tagging server" [5].

Its table lists the tagging server under three directives: img-src, connect-src and frame-src. For a same-origin server the value is 'self'; for a subdomain it is https:// plus your tagging server domain. Worker-src applies to a same-origin server only, and script-src-elem only if you load the Google tag from your tagging server [5]. The field in the previous section reaches the first two directives. Compare Google's list with what your policy already contains, and take any directive the field can't reach to your developer.

Country domains follow a rule Google states plainly: each Google top-level domain "must be specified individually, since CSP syntax does not allow the use of wildcards on the right side of the hostname" [5]. That's why the field takes one host per line, and its example names *.google.de and *.google.co.uk separately. Fixing Google Ads untagged-pages warnings covers the Google Ads side.

Where does the policy actually bite on your checkout?

Adobe says that from 2.4.7, CSP is in restrict mode by default for payment pages in the storefront and admin, and report-only for all other pages [1] [6]. Which pages count as payment pages is narrower than it sounds. In current Magento source (the 2.4-develop branch), the restrict override is set for the checkout page and the multishipping billing step, and the order success page has no override, so it stays report-only [7]. A payment extension or your own config can change that, and your version may differ from the branch.

If that holds on your store, it matters for tracking. Scripts the extension adds at the start of checkout face enforcement, while a purchase script on the success page is more likely to log a warning than to be blocked. "My purchase tag is blocked" is therefore worth testing on the checkout step first and the success page second.

Add a reporting URI too; Adobe documents where in the Admin (Stores > Settings > Configuration > Security > Content Security Policy), with a separate one for the storefront Checkout page [2]. Google recommends report-to directives so you get reports of violations [5]. Verifying GA4 events with DebugView, logs and the preview tools confirms the event reached GA4 once the block is gone.

Leave the checkout in restrict mode

Report-only logs violations instead of blocking them, so the tag would run again, on the page that takes the card. Adobe's overview puts report-only before restrict: "It is safe to switch to restrict mode when no more errors occur", and a poorly configured policy can show "a blank page with numerous console errors" [1]. Adobe means that for rollout.

The WeltPixel Backend module has a setting, off by default, that switches the whole storefront's CSP to report-only; it isn't a fix for a blocked tag [8].

FAQ

Does the extension whitelist my server container?

No. The extension doesn't set the server container URL, so the policy can't learn it from the extension. You add it to the web Google tag, then allow the host in the directives Google lists [5]. On PRO, the Additional CSP Hosts field covers img-src and connect-src [8].

Why is my purchase tag fine but start-of-checkout blocked?

By default, in current Magento source, the checkout page is in restrict mode and the order success page is report-only [7]. A payment extension or custom config can change that, so confirm on your own store with the console and a test order.

Can I fix this from the Admin?

Only for hosts in img-src and connect-src, and only with the PRO extension at 1.17.6 or later [8]. Everything else is a module file, which Adobe says needs a developer or integrator for most merchants [1] [2].

Hash or nonce?

Adobe's KB suggests a nonce for GTM Custom HTML, and warns that a compromised GTM account can sign malicious scripts with it [3]. A hash doesn't carry that warning but can break when GTM rewrites the script [3]. Choose by who can publish in your container.

Does server-side tracking avoid CSP?

For the send to Google, yes: it goes from your Magento server, not the shopper's browser, so the policy doesn't apply to it [8]. Your browser tags still follow the policy.

Let the Magento 2 Google Analytics 4 extension add the hosts of the integrations you switch on to your policy on PRO, and use Additional CSP Hosts for the img-src and connect-src hosts that are yours.

Sources

  1. Adobe, "Content security policy overview", accessed 2026-11-11, https://experienceleague.adobe.com/en/docs/commerce-operations/security-and-compliance/content-security-policy
  2. Adobe Developer, "Content Security Policies", accessed 2026-11-11, https://developer.adobe.com/commerce/php/development/security/content-security-policies
  3. Adobe knowledge base, "Adobe Commerce: Inline JavaScript Issues on checkout page in Content Security Policy (CSP) restricted mode" (Adobe Commerce on cloud infrastructure and on-premises), last update September 17, 2026, accessed 2026-11-11, https://experienceleague.adobe.com/en/docs/experience-cloud-kcs/kbarticles/ka-25030
  4. Adobe knowledge base, "Troubleshoot storefront checkout page in CSP restricted mode", last update October 8, 2026, accessed 2026-11-11, https://experienceleague.adobe.com/en/docs/commerce-knowledge-base/kb/troubleshooting/payments/storefront-checkout-page-in-csp-restricted-mode
  5. Google for Developers, "Content Security Policy (CSP) with Google tags" (last updated 2026-11-10), accessed 2026-11-11, https://developers.google.com/tag-platform/security/guides/csp
  6. Adobe Commerce 2.4.7 release notes, accessed 2026-11-11, https://experienceleague.adobe.com/en/docs/commerce-operations/release/notes/adobe-commerce/2-4-7
  7. Magento 2 source, Checkout and Multishipping modules' etc/config.xml, 2.4-develop branch, read 2026-11-11, https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Checkout/etc/config.xml and https://github.com/magento/magento2/blob/2.4-develop/app/code/Magento/Multishipping/etc/config.xml
  8. WeltPixel Google Analytics 4 User Guide (change log entries for v1.15.3, v1.17.1 and v1.17.6; Additional CSP Hosts admin text) and the GA4 PRO extension package, version 1.17.6, read 2026-11-11, https://docs.weltpixel.com/GA4/User-Guide-WeltPixel-Google-Analytics-4.html

Ready to upgrade your tracking?

Server-side tracking for Magento and Shopify: more of your conversions reach GA4 and your ad platforms, with better attribution.