In autumn 2026, several Magento 2 stores were compromised even though every security patch had been applied. We show how the attackers operated, why a patch alone is not enough and how a daily scanner and a firewall module help.
At a glance
- In autumn 2026, several Magento 2 stores we maintain were compromised even though every patch had been applied.
- A patch closes the vulnerability, but it doesn't remove web shells, session files or crontab entries.
- A daily malware scanner finds what has already got in.
- The SecurityShield module blocks attack patterns before Magento processes them.
- Six practical tips at the end help every store owner.
The call nobody wants to get
A well-maintained, fully patched store suddenly had PHP files in its media folder.
In September 2026, something odd turned up on a Magento 2 store we maintain. Nothing was broken and checkout worked.
But pub/media, which should only hold product images, contained PHP files. There were also PHP session files that didn't look like sessions.
The store had not been neglected. Security patches were up to date, most recently including an Adobe hotfix. Even so, someone else's code was running on the server.
Over the following weeks we saw the same campaign on other Magento stores we look after. Different owners, same pattern. This article describes what we found, what we built in response and the most important lesson:
A patch closes the door, but it doesn't throw out anyone who is already inside.
How the attackers operated
Taken together, the affected stores revealed a clear sequence in five stages.
- Getting in. The attackers used known Magento vulnerabilities: template injection via request parameters, deserialisation via manipulated session data (the SessionReaper family, CVE-2025-54236) and file uploads through features most stores never use, such as old PayPal Payflow endpoints and the file upload in customer addresses.
- Dropping files. Web shells were placed in upload folders (
pub/media/custom_options,customer_address,wysiwyg,tmp) with names meant to look like images. One example:something.shell_PNG.pharwith a trailing space. This is a common trick to get around file extension blocklists. - Session poisoning. Malicious code was stored as a PHP session file containing serialised objects. When PHP loads that session, the objects abuse well-known library classes (logging handlers, HTTP cookie stores) to execute code or write arbitrary files.
- Persistence outside the application. Part of the activity took place in
/tmp,/dev/shmand the actual PHP session directory. These locations sit outside the Magento directory, and nobody looks there. - The frontend. We also found an obfuscated JavaScript loader that fetched further code over a WebSocket connection and executed it with
new Function(). That is the classic pattern of a Magecart card skimmer.
None of these steps requires the vulnerability to still be open. Once a web shell is on disk, it keeps working after the patch.
Why a patch alone falls short
Patching remains essential, but six gaps stay open even afterwards.
We often hear “We're patched, so we're safe.” Patching is essential, and nothing in this article replaces it. But gaps remain:
1. A patch doesn't remove what is already there
A patch fixes the vulnerable code. It does not delete the web shell uploaded the night before, the manipulated session file, the new crontab line or the extra SSH key. If a store was reachable between disclosure and patching, even for just a few hours, you have to assume it may already be compromised.
2. The time until the patch is real
Mass scans for new Magento vulnerabilities often start within hours of disclosure. Testing and deploying a hotfix on a production store, on the other hand, frequently takes days, especially with a custom theme and third-party modules. That is exactly the window attackers use.
3. Patches only cover the Magento core
Real stores include payment modules, PDF libraries and extensions that ship their own copies of third-party libraries. On these stores we had to patch such bundled libraries inside extensions by hand, because the official hotfix didn't cover them.
4. Unused features are still reachable
Most stores have never set up PayPal Payflow or used file uploads in customer addresses. The endpoints exist anyway and respond to requests. A patch makes them safer, but a route that can't be reached at all can't be attacked at all.
5. A patch and a code injection look the same
After a hotfix, a few dozen core files have new timestamps. After an attack, a few core files have new timestamps too. Without a baseline and a record of what changed when, you can't tell the two apart.
6. Error pages become a delivery channel
When malicious input triggers an exception in Magento, Magento writes the request to var/report. The attacker's code ends up as a file on your server. A firewall that rejects the request before Magento processes it prevents that file from being created in the first place.
Our answer: scanner plus firewall
Two components work together: one finds intruders, the other keeps them out.
Component 1: a daily malware scanner
A shell script that runs once a day via cron. It is deliberately quiet: no output means clean, and every finding is emailed to the store owner automatically.
It runs at low CPU and I/O priority, walks the directory tree only once and then searches only that list. A lock ensures two runs never overlap.
It checks:
- File names and extensions:
.phar,.php5to.php9,.phtml, known web shell names, the file names used in this campaign and the trailing space or dot tricks. - Upload and media folders: any PHP code in places that should only contain images, PDFs and CSV files.
- Unknown PHP files in
pub/: anything that isn't one of the known, legitimate entry points. - Session files: serialised objects from known gadget classes and upload progress payloads.
- Temp directories:
/tmp,/var/tmp,/dev/shmand the actualsession.save_pathfrom the PHP configuration. Files owned by other users are included too, because on shared hosting PHP-FPM often runs under a different UID. - Code integrity: modified or missing Magento core files and files in
vendor/that are newer thancomposer.lock. If several files share the same timestamp, this is reported as a likely patch run rather than as 24 separate alerts. - JavaScript: obfuscated loaders and skimmer command-and-control patterns in theme and static files.
var/report: error reports that contain PHP code.- Persistence: suspicious crontab entries, recently modified
authorized_keysand processes running from temp directories. - Forensics: every finding is reported with modification time, size and owner, so the sequence of events can still be reconstructed after the cleanup.
False positives matter as much as hits
A scanner that raises the alarm every morning will be ignored by week two. That is why we tested every change against a full copy of a real store seeded with known malware patterns:
- The 3-byte short tag
<?=on its own flagged 160 of 964 legitimate media files (17%), because those bytes occur by chance in binary data. After the change, PHP short tags only count if real PHP code follows. Result: 0 false positives, 8 of 8 web shell patterns still detected. The new pattern also catches variants such as<?phPthat previously slipped through. - An early rule for session files flagged 5,809 perfectly normal Magento sessions, because every Magento session contains serialised objects. The current rule only matches the specific gadget classes used in these attacks.
- Word boundaries matter: a pattern for
passthru(also matched the harmlessfpassthru(in a PDF library.
Every entry on the exception list was reviewed line by line and given a justification. Every exception is a known blind spot, and we document it as such.
Component 2: a protection module inside Magento
The scanner finds what got in. The SecurityShield module stops it from getting in. It is a small Magento 2 module with two parts.
Part 1, request firewall: It runs before Magento routing for storefront, REST and GraphQL requests and answers attack patterns with 403 Forbidden:
- PHP tags and template directives (
{{block ...}},{{layout ...}}) in URLs, parameters and JSON bodies - References to internal paths (
var/log,var/report,app/etc, path traversal) - Serialised PHP objects and stream wrappers (
phar://,php://) - Overriding the session save path and references to the upload folders used by the SessionReaper chain
- Unused features are switched off automatically: Payflow routes are blocked as long as no Payflow payment method is active, and file uploads in addresses are blocked as long as no file-type address attribute exists. If one of these features is used later, the block lifts itself.
- Uploaded files that contain PHP code, session payloads or serialised objects
Because the request never reaches a controller, no exception is raised and no var/report file containing attacker code is written.
Part 2, upload protection: It hooks into Magento's central file uploader and therefore covers every area, including admin and API. Dangerous file extensions and dangerous content are rejected before the file is written to disk.
Two principles guided development:
- Fail open. If the check itself throws an error, the request goes through and the error is logged. A security module must never take the store down.
- Narrow rules in the admin. CMS content in the admin legitimately contains template directives, so only the PHP tag check applies there.
Rejected requests are written to a dedicated log with rule name, IP and URL, so a false positive can be traced in a few minutes.
Layered security, simply explained
Each layer has strengths and limits; only together do they close the gaps.
| Layer | What it does | What it can't do |
|---|---|---|
| Patching | Removes the vulnerability | Remove an attacker who is already inside; cover bundled third-party code; protect you before the patch is applied |
| Firewall module | Blocks known attack patterns and switches off unused features | Stop an entirely new attack technique |
| Daily scanner | Finds what got through, including outside the Magento directory | Prevent the first upload |
| People | Review findings, keep exception lists honest, check after every patch | Watch the server around the clock |
Each layer covers the gaps of the others. Leave one out and you are betting that nothing goes wrong at exactly that point.
Six tips for every Magento store
These measures help any store spot attacks earlier and make them harder.
- Patch fast, then scan. After every security hotfix, check whether anyone got in before the patch.
- Switch off what you don't use. Payment methods you never set up and upload features you don't need are attack surface.
- Look outside the web root too. Check
/tmp, the PHP session directory, the crontab andauthorized_keys. - Record a baseline. If you know which files a patch changed, an unexpected change stands out immediately.
- Secure evidence before you clean up. Note timestamps and owners first. They reveal how the attacker got in.
- Aim for quiet. On a normal day a security report should be empty. That way a report that isn't empty actually gets read.
Conclusion
A patch closes the door, but it doesn't throw out anyone who is already inside. Only patching, a firewall module, a daily scanner and people who review the findings together cover each other's gaps. As a Magento agency based in Unterföhring near Munich, we're happy to check your store for signs of an attack or set up the scanner and firewall module for you.