Checkout8 min read
How to Find a Malicious or Injected Script in a Shopify Theme
Signs of an injected script or card skimming on a Shopify store, where such code hides, how to inspect your theme step by step, and what to do when you find it.
In this guide
To find a malicious or injected script in a Shopify theme, list every script your storefront loads and account for each one: your theme files, app embeds, web pixels, and code stored in metafields, files and redirects. Anything you can’t trace to your theme, an app you installed or a service you signed up for deserves a closer look. Then search the theme code for the patterns skimming code tends to use, such as code that reads form fields and sends their values to another site, compare suspicious files with their older versions, and restore or remove what nobody can explain.
This guide covers the signs that a script was injected, where such code hides on a Shopify store, how to inspect it step by step without a developer, and what to do when you find something.
Signs that something was injected
None of these proves an attack on its own, and most have harmless explanations. Each one is a reason to check:
- Customers report card fraud shortly after buying from you, or your payment provider asks about a pattern of disputes.
- Browsers show a “dangerous site” or “deceptive site” warning on your store. You can check your domain in Google’s Safe Browsing site status.
- Checkout leaves your domain. After clicking Check out, the address bar shows a site that is neither your store nor Shopify’s checkout.
- An extra payment or login form appears on a page where you never added one, often a pop-up asking for card details before checkout.
- Your theme changed and nobody remembers changing it. A file in the code editor has a recent version nobody on your team can explain.
- New sites load on your pages. The browser’s Network tab shows scripts from domains you don’t recognise.
How skimming works on a Shopify store
On Shopify, the card fields at checkout are a secure frame hosted by Shopify. A script on your storefront runs on a different origin and can’t read what a shopper types inside that frame. That narrows what an injected script can do, but it doesn’t make it harmless. It can still:
- show a fake payment form on your storefront, before the real checkout, and send what the shopper types to another site;
- read other fields on your pages, such as login, address or newsletter forms;
- send shoppers to a look-alike checkout on another domain;
- load further code from a server the attacker controls, so the visible part in your theme stays small.
That is why the checks below focus on two questions: which code runs on your pages, and where it sends data.
Where injected code hides on Shopify
| Place | Where to look in the admin | What to look for |
|---|---|---|
| Theme files | Online Store > Themes > Edit code: layout/theme.liquid, snippets, sections, assets/*.js |
Script tags or inline code you didn’t add |
| App embeds and app blocks | Themes > Customize > App embeds, and settings of app blocks | Embeds from apps you removed, custom code entered in a setting |
| Web pixels | Settings > Customer events | Custom pixels nobody remembers adding |
| Metafields and metaobjects | Settings > Custom data | HTML or <script> stored in a field the theme prints without escaping |
| Files | Content > Files | .js or .html files nobody uploaded on purpose |
| Redirects and menus | URL redirects, Online Store > Navigation | Redirects or menu links to unknown sites |
| Checkout | Settings > Checkout, Settings > Payments | Checkout apps or payment providers you didn’t set up |
Code served by an app embed lives on the app’s servers, not in your theme. When the app changes that code, nothing in your theme changes, so a theme-only review misses it. The only way to see it is to look at what actually loads in the browser.
Step by step: inspect your store
1. See what loads in a shopper’s browser
Open your store in a private window. Open the browser’s developer tools, go to the Network tab, filter by JS and reload. Write down the domains the scripts come from on the home page, a product page and the cart. Expect your own domain, Shopify’s (cdn.shopify.com and similar) and the apps and services you use. Every other domain needs an owner.
2. Search the theme code
In Online Store > Themes, duplicate the live theme first, then open Edit code and use the search for:
<scriptwith ansrcpointing outside your domain and Shopify;eval(,atob(,String.fromCharCodeand long blocks of random-looking letters, which are ways to hide what code does;document.createElement('script'), which loads more code at run time;- names of card fields such as
cc-number,cvvorcard_numberin code that isn’t part of a payment app you use; fetch(,XMLHttpRequestorsendBeaconsending data to a domain you don’t know.
Many legitimate apps use some of these. A match is a reason to find out which app or person added the code, not proof of an attack.
3. Compare with older versions
Shopify keeps older versions of each theme file. Open a suspicious file, choose an earlier version and compare. If code appeared on a date when nobody worked on the theme, note the date: it helps when you talk to Shopify Support or an app developer.
4. Check app embeds, pixels and store data
Go through the rows of the table above: turn off app embeds from apps you no longer use, remove custom pixels nobody can explain, and check Content > Files, redirects and menu links. Ask your developer whether any metafield holding HTML is printed without the escape filter.
5. Click through checkout
Add a product to the cart and click Check out. Checkout should open on your domain or Shopify’s checkout. If it ends anywhere else, treat it as urgent.
What to do when you find something
- Don’t just delete it. Copy the code, the file name, the domain it loads from and the date into a note. Take screenshots.
- Find the owner. If it belongs to an app, ask the app’s developer whether it is theirs and why it changed. If it was a freelancer or agency, ask them.
- Remove or restore. Restore the theme file to a clean earlier version, or publish the copy you duplicated before the change. Turn off the app embed or pixel, or uninstall the app.
- Close the way in. Change staff passwords, make two-step authentication required for every user, remove accounts and collaborators you don’t need, and uninstall unused apps. The Shopify store security checklist and the staff permissions guide cover each step.
- Tell Shopify and your payment provider. Contact Shopify Support if you think your store was changed without your permission. If card data may have been exposed, contact your payment provider or acquirer, and get legal advice on whether you must inform customers.
- Watch for it coming back. Check the same places again over the following weeks. Code that returns after removal usually means the way in is still open.
Where Custos: Store Security Scan fits
Doing steps 1 to 5 by hand once is useful. Repeating them every week, on every page, is the part that slips. Custos: Store Security Scan automates it:
- It reads your live theme for scripts from other sites and for code patterns used by card skimmers, such as code that listens to card-like input fields or sends data to sites that are not part of your store.
- A browser on the app’s server walks your store like a shopper, from the home page through a collection, a product, search and the cart to the customer account and checkout, stopping at the payment step. On each page it records every script, a fingerprint of its content and the sites it talks to.
- The first scan is your baseline. Later scans report what is new, changed or removed: a new script, an app’s code that now serves different content, a new pixel destination, or a checkout that ends on a site that is not your store’s domain or Shopify’s checkout.
- It checks metafields, metaobjects, files, redirects and menu links for scripts and links to unknown sites, and flags metafields your theme prints without escaping.
- Each finding comes with steps to fix it and a link to the right page of your admin. See reading findings.
What it does not do: it doesn’t remove or block anything, it never labels an app as compromised, and it can’t promise to find every kind of malicious code. Code that loads only for some visitors, on pages the walk doesn’t visit or between two scans may be missed; what the scan cannot see lists those limits.
Install Custos: Store Security Scan from the Shopify App Store and run the first scan to see every script, app embed and pixel on your store today.
FAQ
Can a script in my Shopify theme steal card numbers?
It can’t read inside the card fields of Shopify’s checkout, which are a secure frame on Shopify’s domain. It can show a fake payment form on your storefront, send shoppers to a fake checkout, or read other forms on your pages. Those are the cases to check for.
Is there a Shopify malware scanner that finds everything?
No tool can promise that. A scanner can report what is new or changed in the code that reaches your shoppers and flag known risky patterns. It can’t judge intent, see what an app does on its own servers or see code that loads only in some conditions.
Does uninstalling an app remove its code from my theme?
App embeds and app blocks are removed with the app. Code that an app or a developer pasted into theme files stays until someone deletes it, so check your theme after uninstalling older apps.
How do I know if a script is from an app I installed?
Look at the domain it loads from and search for it together with the app’s name, or ask the app’s developer. Turning off one app embed at a time in the theme editor and reloading the page also shows which embed loads which script.
Should I tell my customers?
If card data or personal data may have been exposed, talk to your payment provider and a lawyer. Notification duties depend on where you and your customers are.