Skip to content

Protect WooCommerce From Magecart at Checkout

Laís Peixoto

By Laís Peixoto

Growth Marketer, Proteside

Published · 5 min read

Payment QR code with a fake layer peeling off on top, next to the Proteside shield. Payment methods: Credit card and Pix.

To protect a WooCommerce store from Magecart, keep few plugins and update all of them, limit and secure admin accounts, turn off the dashboard file editor and monitor file integrity. Finally, check in the buyer's browser that the Pix QR code and the credit card form shown are the ones the store issued.

To protect a WooCommerce store from Magecart (the name given to attacks that insert malicious code into the payment page to copy card data or divert the payment), you need to cover four areas: plugins and themes, updates, access accounts, and checking what the payment page shows to the buyer. A server that looks clean does not close the matter, because the scam happens on the screen of the person paying.

What has already happened in WooCommerce stores

In April 2020, researcher Ben Martin of Sucuri described the case of a WordPress store running WooCommerce whose customers reported fraudulent card charges shortly after buying on the site. The first scan found only generic backdoors (code that lets the attacker get back into the site). The code that copied the data only showed up in an integrity check of the core WordPress files.

A few details from the report help explain the risk:

  • The malicious code was placed inside a legitimate file, the jQuery library that WordPress itself uses. Changing a file that already exists makes the change harder to notice than adding a script from another address.
  • The attackers created a PHP file with a name similar to system files and loaded it from functions.php. That file stored the card number and security code in files with an image extension in the uploads folder.
  • Those files were already empty when the analysis began. According to the researcher, the most likely explanation is that the code itself erased the traces after delivering the data.
  • The point of entry was not confirmed. The hypotheses mentioned were a compromised administrator account, the SFTP password, the hosting password or some vulnerable software.

The same article notes that earlier attacks on WooCommerce stores usually changed the plugin's payment settings, for example by sending payments to the attacker's PayPal email. Commenting on the case, Threatpost's coverage notes that, in general, sites tend to be breached through plugins with known flaws or through administrator passwords found by trial and error. For those who sell with Pix (Brazil's instant payment system), the lesson is similar: the target can be where the money goes, not just the card data.

The case dates from 2020. Of the steps below, 4 and 5 follow the researcher's own recommendations; the others are general maintenance practices for any WordPress store.

Step by step to protect the WooCommerce checkout

  1. Trim plugins and themes. Every installed extension is third-party code running in your store, including on the payment page. Remove what you do not use (deactivating is not enough, the file stays on the server). The post on compromised plugins, themes and third-party scripts explains how a compromised plugin or theme reaches the checkout.
  2. Update on a routine. WordPress, WooCommerce, plugins, themes and the hosting PHP version need a fixed schedule, not updates only when something breaks. If possible, test first on a copy of the store and apply security fixes quickly.
  3. Reduce and protect access accounts. Keep few people with the administrator role in WordPress, and use two-step verification. Apply the same care to the hosting panel and SFTP, which appear among the hypotheses for the entry point in the Sucuri case.
  4. Turn off the dashboard file editor. The Sucuri researcher's recommendation is to set the DISALLOW_FILE_EDIT constant to true in the wp-config.php file. That way, not even an administrator can edit theme and plugin files from the dashboard. If an account is stolen, this can keep the attacker from planting the malicious code.
  5. Check file integrity. Periodically compare the WordPress and WooCommerce files with the official versions and monitor changes to themes and plugins. PHP files inside the uploads folder and new files with names similar to system files deserve investigation.
  6. Watch the payment receiving settings. Pix key, destination account, gateway credentials and receiving email should have an owner, a change log and an alert when they change. A swap here diverts the payment without touching the form.
  7. Check the payment page in the buyer's browser. The previous steps protect the server, but what matters to the customer is what appears on their screen. Check that the QR code and the Pix Copia e Cola (Pix copy-and-paste code) shown are the same ones the store generated and that the credit card form is the original. The guide on how to detect malicious JavaScript at checkout covers the most common signs.
  8. Treat customer complaints as an alert. In the case described by Sucuri, the first sign was customers reporting fraud right after purchase. Have a response plan ready that includes notifying the payment provider.

What changes for those who accept credit cards

Stores that accept credit cards also need to consider PCI DSS requirements 6.4.3 and 11.6.1, which cover payment page scripts and the detection of changes to the page. The text on what PCI DSS 6.4.3 and 11.6.1 require summarizes what must be inventoried and monitored. For Pix, the equivalent care is to check that the QR code and key shown are the ones issued by the store, as the page on Pix protection at checkout shows.

Platforms and agencies that maintain many WooCommerce stores can standardize these steps for all clients. The page on security for e-commerce platforms shows how checking the payment page fits into that routine.

In short

No single measure solves it: lean plugins, up-to-date software and well-guarded accounts lower the chance of a breach, and the browser check covers whatever slips through. Proteside has a free WooCommerce plugin that compares the payment the store issued with what the buyer sees, and blocks confirmation when the two do not match.

How we create our content

Back to blog