On this page
What this issue is
Most websites load code they did not write. It comes from npm packages bundled into your build, or from a CDN (content delivery network, a server that hosts shared files) through a <script src> tag. This is called your supply chain.
A compromise happens when an attacker takes over a package maintainer account, publishes a poisoned version, or takes control of a CDN domain or file. Your site then serves the attacker's code to every visitor, with the same access as your own scripts. That code can read form fields, redirect visitors, inject fake fields or send data elsewhere.
- Library publishedPackage or CDN file is trusted
- Attacker alters itStolen account or hijacked domain
- Your page loads itNew build or live CDN request
- Visitor affectedRedirects, skimming, fake forms
The attacker never touches your server. They change code you already trust.
Why it costs you leads or sales
Malicious code can redirect visitors to other sites, swap your form for a copy, or siphon off personal and payment details. You lose conversions while it runs, and you may also face browser or search engine warnings, ad account suspensions, data breach duties and lost customer trust.
It is often silent. Pages look normal to you, because the code may target only some countries, devices or visitors who came from ads.
Day 0
A library you load from a CDN is altered.
Day 1
Some visitors are redirected or see fake fields. Your own tests look fine.
Day 5
Conversion rate drops; customers report odd behaviour.
Day 6
Security notice published. You remove or pin the library.
How to check if your site has it
List every external script
Open your page, view source and search for
<script src=. In Chrome DevTools, the Network tab filtered to JS shows each domain. Note anything on a public CDN.Run a dependency auditCustom code
In your project run
npm audit(oryarn audit,pnpm audit). It lists known vulnerable or malicious package versions.Check your lockfileCustom code
Review package-lock.json for versions that changed unexpectedly in recent commits.
Read the advisories
Search the package name in the GitHub Advisory Database and the library's issue tracker for reports of a hijack.
Compare what is served with what you expect
Download the live file with curl and compare its hash with a known good copy.
curl -s https://cdn.example.com/lib@1.2.3/lib.min.js | openssl dgst -sha384 -binary | openssl base64 -AHow to fix it
Remove or disable the affected script
Take it off the page now. A missing widget costs less than a malicious one.
Replace with a known good version
Install a version published before the compromise, or switch to a trusted alternative. Rebuild and redeploy.
Pin exact versionsCustom code
Use exact versions in package.json (no ^ or ~) and commit the lockfile. Install in CI with
npm ci.Add SRI or self-host
Add an integrity hash to CDN scripts so the browser refuses a changed file, or host the file on your own domain.
Rotate secrets
If the script could reach tokens, API keys or admin sessions, rotate them and force logouts.
<script src="https://cdn.example.com/lib@1.2.3/lib.min.js"
integrity="sha384-REPLACE_WITH_YOUR_HASH"
crossorigin="anonymous"></script>Find the source
Check Plugins and your theme for the script. Update or deactivate the plugin that loads it. Look in functions.php for wp_enqueue_script calls with external URLs.
Self-host
Download a verified copy into your theme folder and enqueue it locally.
Check theme and apps
In Online Store > Themes > Edit code, search theme.liquid for the script URL. Remove unused apps under Settings > Apps and sales channels.
Check Customer events
Review Settings > Customer events for custom pixels loading external code.
Audit Custom HTML tags
Open Tags and search for Custom HTML tags that load external src URLs. Pause them, then check Versions to see who changed what.
Check custom code
Review Site settings > Custom code (head and footer) and page-level custom code for external scripts. Remove, then publish.
Check tracking code fields
Review the header and footer tracking code in Funnels and Websites settings, and custom code elements on pages.
Check custom code
Open Settings > Custom code and review each snippet and its pages. Remove unknown ones.
Check code injection
Review Settings > Advanced > Code Injection (header, footer) and Code Blocks on pages.
Audit and rebuild
Search the codebase for external script URLs, update the lockfile to a clean version, rebuild and deploy.
Content-Security-Policy-Report-Only: script-src 'self' https://www.googletagmanager.com https://cdn.example.com; report-uri /csp-reportBefore
- Script loaded from a CDN with a floating version like @latest
- No integrity hash
- Nobody reviews dependency updates
After
- Exact version pinned and lockfile committed
- SRI hash or self-hosted file
- CSP allowlist and update reviews
How to confirm it's fixed
- The affected script no longer appears in view source or the DevTools Network tab
npm auditreports no known malicious or critical packages- CDN scripts carry integrity hashes and load without console errors
- Forms and checkout work and show no unexpected fields or redirects
- CSP report-only logs show no unknown script domains
- Passwords, keys and tokens that could have been exposed are rotated
How to prevent it happening again
- Pin exact versions and commit lockfiles
- Use
npm ciin builds and review dependency update pull requests - Add SRI to every third-party script that supports it
- Self-host critical libraries, especially on checkout pages
- Keep a written list of approved script domains
- Enable a CSP and review its reports
- Remove libraries you no longer use
- Turn on two-factor authentication for your npm, GitHub and CDN accounts
How FunnelGuard handles this
This issue is outside what FunnelGuard checks. FunnelGuard runs your real customer journeys on a schedule and checks each step, tracking hits and test lead delivery. It is not a code scanner and does not inspect the contents of your scripts or dependencies.
The kinds of tool that fit are a software composition analysis or dependency scanner (such as npm audit, GitHub Dependabot or similar) for packages, and a client-side script monitoring tool or CSP reporting for what runs in visitors' browsers. A broken form or checkout step caused by a bad script is a separate symptom that journey monitoring can show, but that is not the same as finding the compromise.
Questions people ask
How do I know if an npm package I use has been compromised?
Run npm audit and check the GitHub Advisory Database and the package's issue tracker. Also review your lockfile for versions that changed unexpectedly. Enable Dependabot or a similar scanner to get alerts automatically.
What is Subresource Integrity (SRI) and does it stop a compromised CDN?
SRI adds an integrity hash to a script tag. The browser compares the downloaded file with the hash and refuses to run it if it differs. It protects you if the CDN file is changed, but only for files that never change legitimately, so pin an exact version.
Why is my website redirecting visitors to another site?
A common cause is a third-party script or tag that has been changed to inject redirects, including a compromised CDN library. Check external scripts, Custom HTML tags in your tag manager and plugins, and remove anything unfamiliar.
Should I self-host JavaScript libraries instead of using a CDN?
Self-hosting removes the risk of the CDN file changing without your knowledge, as long as you download from a trusted source and update deliberately. It is a good choice for critical pages like checkout. You then own the job of applying security updates.
What should I do first if a library I use was compromised?
Remove or disable the script, then replace it with a known good version and redeploy. Rotate any keys or sessions it could reach and check whether visitor data was exposed. Review legal notification duties if forms or payments were affected.
Does a Content Security Policy prevent supply chain attacks?
It limits them. A CSP with a script-src allowlist blocks scripts from domains you did not approve, but a compromised script on an allowed domain can still run. Combine it with SRI, pinned versions and dependency scanning.
Can FunnelGuard detect a compromised library?
No. FunnelGuard checks journeys, tracking hits and lead delivery, not the contents of your scripts. Use a dependency scanner and a client-side script monitoring tool for this.
Related issues
- OPS-195Magecart / card skimmer script on checkoutFix guide
- OPS-196Unknown third-party domain appears on checkout pageFix guide
- OPS-198Abandoned script domain re-registered by attackerFix guide
- OPS-199Tag manager container edited by unknown userFix guide
- OPS-200Too many third-party scripts (performance and risk)Fix guide
- OPS-206Ad network script injecting redirectsFix guide