Why nested deserialization is harmful: Magento XXE (CVE-2024-34102)
Magento's REST API deserialisation logic allowed unauthenticated attackers to instantiate a SimpleXMLElement with controllable arguments, leading to XML external entity (XXE) injection. This could let an attacker read local files such as app/etc/env.php, which contains a cryptographic key that can be used to forge administrator JWTs.
Magento is one of the most popular e-commerce solutions in use on the internet. It's estimated that there are over 140,000 instances of Magento running as of late 2023.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the recursive deserialisation in Magento's ServiceInputProcessor allowed user-controlled JSON to instantiate arbitrary classes, including SimpleXMLElement with external entity loading enabled.
Impact
An attacker could exfiltrate the app/etc/env.php file and use the cryptographic key to forge an administrator JWT, potentially leading to remote code execution when chained with other techniques.
What the attacker needed
Magento version before 2.4.7-p1; No authentication required; Attacker can host a DTD
The fix
The vulnerability was fixed in Magento 2.4.7-p1 by preventing the instantiation of SimpleXMLElement with external entity loading.
How it was found
- Identify the unauthenticated endpoint /rest/all/V1/guest-carts/test/estimate-shipping-methods as a candidate to reach sourceData.
- Craft a JSON payload that nests objects to instantiate SimpleXMLElement with a malicious XML document via the sourceData parameter.
- Host a DTD that defines an external entity to read a local file and exfiltrate it to an attacker-controlled server.
- Send the request and observe the exfiltrated file contents.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Magento is an e-commerce platform. Its API automatically converts JSON input into internal objects, and this process could be tricked into creating an XML parser that loads external files. An attacker could then read sensitive files on the server, including a secret key that allows them to pretend to be an administrator.
What is XXE?
An XML parser resolves entities the attacker defines, reading local files or making the server send requests.