Magecart is the collective name for web skimming attacks in which criminals inject malicious JavaScript into online checkout pages to capture payment card numbers, expiry dates, security codes and personal details as customers enter them. E-commerce operators treat Magecart as one of the most damaging threats in payment security, because the theft happens inside the shopper’s browser, before the data ever reaches the payment processor.
The name originally referred to criminal groups that targeted stores built on the Magento platform, but it now describes a whole attack technique used by many unrelated groups against any web storefront. The synonym web skimming reflects the analogy with physical card skimmers attached to ATMs and fuel pumps: the card is read silently while the legitimate transaction still completes.
How a Magecart attack steals card data
A Magecart attack works by placing attacker-controlled code on a page where customers enter payment details and sending a copy of every keystroke or form submission to a server the attacker controls. The checkout continues normally, so neither the shopper nor the merchant sees an error, and the order is processed as usual.
The typical attack chain has four stages. First, the attacker gains write access to a script source, either the store itself or a third-party service that the store loads. Second, the attacker adds a skimmer script, often obfuscated and disguised as an analytics or tag manager file. Third, the skimmer hooks form fields or the submit event and collects card data in the browser. Fourth, it exfiltrates the data to a lookalike domain, frequently through an image request, a WebSocket or a fetch call that blends into ordinary traffic.
The following table summarizes the stages and the defensive signal each one can leave.
| Stage | What the attacker does | Possible detection signal |
|---|---|---|
| Initial access | Exploits a CMS flaw, stolen admin login or vendor compromise | Unexpected admin logins or file changes |
| Script injection | Adds or modifies JavaScript on payment pages | Changed script hash or new script source |
| Data capture | Reads form fields or intercepts submit events | New event listeners on card inputs |
| Exfiltration | Sends data to an attacker domain | Outbound requests to unknown hosts |
Some variants go further and inject a fake payment form on stores that normally redirect to a hosted payment page. The shopper enters card data into the counterfeit form, sees a generic error, and is then sent to the real payment page, so the transaction still succeeds and suspicion stays low.
Attack vectors and Magecart variants
Magecart campaigns differ mainly in where the malicious code is introduced. The vector matters because it decides which team can prevent the attack and how many stores are affected at once.
| Vector | Typical scope | Main weakness exploited |
|---|---|---|
| First-party compromise | One store | Unpatched platform, plugin or weak admin credentials |
| Third-party supply chain | Hundreds or thousands of stores | Compromised chat, analytics or advertising script |
| Open cloud storage | Every site loading the bucket | Publicly writable storage hosting JavaScript files |
| Malicious browser extension | Individual shoppers | Extension with broad page access rights |
| Server-side skimmer | One store | Backdoored PHP or server code capturing posted data |
Supply chain attacks produce the largest incidents. A single compromised vendor script can reach every merchant that embeds it, which is why security teams treat each external tag on a checkout page as a potential point of failure. Server-side variants are rarer but harder to see, because the malicious logic never appears in the code delivered to the browser.
Magecart compared with related payment fraud
Magecart is a data theft technique, not a fraud method in itself; the stolen cards later fuel other schemes. Distinguishing it from neighboring concepts in payment security helps teams assign responsibility correctly.
| Concept | Where it happens | Relationship to Magecart |
|---|---|---|
| Magecart | Merchant checkout in the browser | Source of stolen card data |
| Card testing | Merchant payment endpoints | Often used to validate skimmed cards |
| Card-not-present fraud | Other online stores | Main monetization of skimmed data |
| Physical card skimming | ATMs and point-of-sale terminals | Offline analog of the same idea |
| Phishing | Fake sites and messages | Lures shoppers away rather than hijacking a real site |
Because the skimmer captures the full card number and CVV, the stolen data supports card-not-present purchases elsewhere. Fraud screening, velocity checks and address verification at other merchants are therefore the downstream defenses, while the breached merchant faces forensic investigation, card reissuance costs and possible penalties.
Defending checkout pages against web skimming
Effective Magecart defense controls which scripts run on payment pages and detects changes quickly. No single control is sufficient, so mature merchants layer several measures.
- Content Security Policy (CSP) restricts the domains from which scripts may load and to which data may be sent.
- Subresource Integrity (SRI) pins a cryptographic hash to an external script so that a modified file is refused.
- Script inventory and change monitoring records every script on payment pages and alerts on new or altered code.
- Hosted payment fields or iframes from the processor keep card entry outside the merchant’s page context.
- Patching and strong admin authentication close the most common first-party entry points.
PCI DSS version 4.0 made this explicit for card environments. Requirement 6.4.3 demands an authorized inventory and integrity checks for payment page scripts, and requirement 11.6.1 demands a mechanism that detects unauthorized changes to page content and HTTP headers, both mandatory since March 2025.
The table below helps match controls to the merchant’s checkout architecture.
| Checkout model | Residual Magecart risk | Priority controls |
|---|---|---|
| Full redirect to processor | Low, but fake form injection remains | Monitor the page that triggers the redirect |
| Embedded iframe fields | Moderate, parent page can be altered | CSP, script inventory, integrity monitoring |
| Direct post or custom form | High, card data touches merchant code | All layers plus server-side code review |
Limitations and common mistakes
The most frequent mistake is assuming that outsourcing payments removes the risk. Iframes and redirects reduce exposure, yet an attacker who controls the parent page can still overlay a fake form or alter the redirect target.
- Overly permissive CSP rules, such as allowing whole content delivery networks, let attackers host skimmers on trusted domains.
- SRI cannot protect dynamic scripts that vendors change frequently, so it must be combined with monitoring.
- Periodic scans miss conditional skimmers that activate only on checkout pages, specific geographies or real browsers.
- Dwell time is long: skimmers often run for weeks or months before discovery, multiplying the number of compromised cards.
Detection is complicated by heavy obfuscation and by skimmers that load only for a fraction of visitors. Monitoring therefore works best when it observes the page as a real browser does, including the scripts that third-party tags load dynamically.
Stripped to the essentials
Magecart is a way of stealing card details from a real online shop. Criminals secretly add a small piece of code to the payment page. When you type your card number, the code quietly sends a copy to the criminals, while your order still goes through normally.
It is like a hidden camera above a shop’s card reader: the purchase works, so nobody notices anything. The key point is that the shop itself looks genuine, so careful shoppers can still be affected, and the main responsibility for prevention lies with the store.
Where it is applied
A mid-sized online retailer of outdoor equipment loads 14 third-party scripts on its checkout, including chat, analytics and a review widget. An attacker compromises the chat vendor and adds 40 lines of obfuscated code that copy card fields to a domain resembling the vendor’s own. For six weeks, roughly 9,000 orders are processed normally.
The breach surfaces when the card networks flag the store as a common point of purchase for fraudulent transactions. Forensic investigators find the altered chat script, and the retailer must notify customers and fund card reissuance.
Afterward, the retailer moves card entry to processor-hosted iframe fields, removes nine nonessential scripts from payment pages, deploys a strict CSP and adds real-time script change monitoring. A later attempt to modify a remaining script triggers an alert within minutes and is blocked before any card data leaves the page.