# Insecure Deserialization
> Reconstructing attacker-controlled serialized data with a mechanism that can instantiate arbitrary types and run their callbacks, so that choosing the bytes becomes choosing the program's behaviour — classically remote code execution (CWE-502).
## What it is
Serialization turns an in-memory object graph into bytes for storage or transport; deserialization rebuilds it. The vulnerability is a trust-boundary failure: an application hands a native object format bytes that a user can modify, and the deserializer does more than read data — it names a type, constructs it, and runs code while doing so. A data-only format (JSON, MessagePack, Protobuf) can only describe strings, numbers, booleans, null, lists and maps, so the worst a hostile document can do on its own is be an unexpected value. A native object format — Python pickle, PHP `serialize()`, Java `ObjectInputStream`, .NET `BinaryFormatter`, Ruby `Marshal` — can name a class, ask for an instance, and (pickle) name any callable. The question the deserializer answers is not "what data is this?" but "what should I construct, and what runs while I construct it?" (DedSec, OWASP CWE-502).
Three conditions make it dangerous (Mandiant): the serialized object is attacker-controllable; the app deserializes it without validation; and the deserializing process has useful classes on its classpath/importable. The last is why the **same vulnerable line is RCE on one deployment and inert on another** — exploitability is a property of what code is loadable, not of the bug alone.
## Why it matters
- **Impact ladder.** Benign-looking state tampering (changing a quantity, a username, a role) → object injection and logic subversion → denial of service → authentication bypass → remote code execution, frequently unauthenticated and pre-auth. It is a perennial OWASP Top 10 category spanning C/C++, Java, PHP, .NET, Python, Ruby and Node.
- **Severity drivers.** Reachability (pre-auth network sink vs. authenticated import), the privilege of the deserializing process (root containers, SYSTEM services), and classpath richness. Many 2025–26 cases are CVSS 9.8–10.0.
- **Real breaches.** The Equifax breach traced to Apache Struts (CVE-2017-5638); APT41 used .NET ViewState and Java chains against governments and enterprises (Mandiant); SharePoint "ToolShell" (CVE-2025-53770) and WSUS (CVE-2025-59287) saw mass in-the-wild exploitation; DELMIA Apriso (CVE-2025-5086) and Apache Roller (CVE-2026-129448) reached CISA KEV.
## How it works
The deserializer rebuilds the graph and, along the way, invokes callbacks the attacker's chosen types define. Linking those callbacks from an entry point to a dangerous sink is a **[[Gadget Chains|gadget chain]]** (Property-Oriented Programming): existing, benign code reused in an unexpected order, injecting nothing new. The mechanics differ by stack, each with its own page:
- **[[Java Deserialization]]** — `ObjectInputStream.readObject()` and JVM marshallers (XStream, Hessian, Kryo, AMF, SnakeYAML); collection re-hash as the kick-off; JRE/Xalan bytecode and JNDI sinks; JDK 17+ module encapsulation reshaped the landscape.
- **[[PHP Object Injection]]** — `unserialize()`, `maybe_unserialize()`, and the implicit `phar://` metadata path; `__wakeup`/`__destruct` and POP chains in plugins/libraries.
- **[[Python Pickle Deserialization]]** — `pickle.loads()` and everything built on it; `__reduce__` can call any importable callable; the ML-model format problem.
- **[[NET Deserialization|.NET Deserialization]]** — `BinaryFormatter`/`LosFormatter`/`ObjectStateFormatter`, type-binding JSON/XML, and ASP.NET ViewState keyed on `machineKey`.
- **[[Polymorphic Deserialization]]** — JSON/YAML/XML/BSON bugs where the document names the concrete type (`$type`, `@type`, AutoType, `!!python/object`, Puppet `__ptype`), re-introducing object injection into "data" formats.
- **Data files whose fields are evaluated** — not a deserializer at all, but the same trust failure: yt CVE-2026-132751 restores a saved HDF5 dataset's `con_args` attribute with `eval()` (CWE-95), so `yt.load()` on a shared file runs its author's Python ([[raw/r3vpwnx.medium.com/loading-a-dataset-should-not-run-code-15851|Loading a dataset should not run code]]). See [[Code Injection]] and [[Model Deserialization Attacks]].
- **Ruby `Marshal`** — `marshal_load`/`_load`/`_load_data` and implicit kick-offs (`hash`, `eql?`); covered within [[Gadget Chains]].
## Where to find it
Serialized values surface in cookies and session stores, non-HTTP platform listeners the server profile enables (WildFly IIOP on 3528, read before auth in 32-35), config-management channels (Puppet agent reports on 8140), hidden form fields (ViewState), headers, query/body parameters, import/upload files, caches and message queues (Redis/Celery/Kafka/ZeroMQ), RPC/management ports (RMI, JMX, T3, .NET Remoting, gRPC), and model/checkpoint files. Recognise formats by their first bytes:
| Format | Hex | Base64 begins |
|---|---|---|
| Java native | `AC ED 00 05` | `rO0AB` |
| Pickle proto 2/3/4/5 | `80 02`/`80 03`/`80 04 95`/`80 05 95` | `gAJ`/`gAN`/`gASV`/`gAWV` |
| PHP object / array | `O:5:"..."` / `a:1:{` | `Tzo` / `YTo` |
| .NET BinaryFormatter | — | `AAEAAAD/////` |
| ASP.NET ViewState | — | `/wE` |
| Ruby Marshal | `04 08` | `BAh` |
| Node `node-serialize` | marker `_$ND_FUNC$_` inside JSON | — |
| gzip wrapper (any of the above) | `1F 8B 08` | `H4sI` |
Decode and check the actual bytes — a two-character base64 prefix collides by chance (~1 in 4096), while `gASV`/`rO0AB`/`H4sI` do not (DedSec measured).
## How to test
A finding is a claim about a chain of four facts, each with its own evidence (DedSec):
1. **Accepted** — the server took the blob. Evidence: a response. (A 200 proves *only* acceptance.)
2. **Parsed** — a deserializer read the bytes. Evidence: a *format-specific* error from a truncated/corrupted copy of the app's own value (`pickle data was truncated`, `unserialize(): Error at offset N`). A generic 500 proves nothing.
3. **Instantiated** — a named class was constructed. Evidence: the class name or its side effect (PHP `bad session: CacheWarmer` vs `__PHP_Incomplete_Class`).
4. **Executed** — attacker-chosen code ran. Evidence: an effect only execution causes — an **out-of-band callback carrying a per-request token**, or a computed marker.
Methodology:
- Decode the value; note whether it is signed (separator + second component) and/or compressed.
- Prove the deserializer runs by replaying the app's own value with trailing bytes removed, then corrupted.
- Confirm with an OOB payload first — one unique token per request to an HTTP **and** DNS listener (Java's `URLDNS`, a Python/pickle stdlib callback; for PHP/Java RCE you need a gadget loadable in the target, so record which one). See [[Out-of-Band Detection]].
- Use time only with controls: a non-sleeping payload of the same format, and ideally a delay that scales — a delay on the failure path (a login/bad-session throttle) is a classic false positive.
- On a handler that returns an identical response to every failure, the response cannot confirm or refute anything; only an out-of-band effect can.
- For a signed value, test ordering: an OOB payload under a deliberately wrong signature should produce no callback; if it does, verification runs *after* deserialization. Separately, check whether the signing key is leaked.
**Checklist:** decode and identify format → signed/compressed? → prove parse (truncate/corrupt) → OOB payload with unique token (HTTP+DNS) → time only with same-format non-sleeping control → look outside the response → record negatives precisely ("no callback from *these* gadgets").
## Exploitation and escalation
Impact is whatever the chain's sink does, and depends on what is loadable — see [[Gadget Chains]] for the kick-off/helper/bypass/sink anatomy and per-language entry points and sinks. Escalation paths seen in the corpus: ViewState/`machineKey` disclosure → signable deserialization sink ([[NET Deserialization|.NET Deserialization]]); leaked Flask `SECRET_KEY` reused from an OAuth secret → forgeable pickle cookie → unauth RCE (Google, $90k); pre-auth parameters bypassing earlier allowlist patches (OpenAM CVE-2026-33439); cache/queue poisoning (rConfig Laravel Horizon, AWS JDBC wrapper); and post-RCE pivots to CA signing keys (Puppet/OpenVox CVE-2026-115731). Deserialization is a frequent high-value link in a [[Vulnerability Chaining|chain]] to [[Remote Code Execution]].
## Bypassing defenses
Common failures of partial mitigations (observed in the corpus and lab-measured by DedSec):
- **Validation that runs too late or sees too little.** WildFly 32-35 authenticated IIOP calls only after unmarshalling the parameters; jackson's PTV checked only the outer class of `ArrayList<Gadget>` (CVE-2026-54512). The review question is whether the check runs *before* the dangerous operation and inspects *everything* it will use ([[raw/chern0b.it/two-roads-to-rce-in-wildfly-pre-auth-corba-deserialization-and-json-pa-15864|WildFly two roads]]).
- **Authenticated-only sinks with weak enrollment.** Puppet's report deserializer needs a CA-signed agent cert, but weak autosign hands one to anyone ([[raw/blog.ostorlab.co/puppet-server-deserialization-rce-cve-2026-115731-ostorlab-15875|Ostorlab Puppet]]).
- **Blocklists/denylists** trust every class they did not name. UltraRed built a working chain from Oracle Coherence + Xalan classes a custom blocklist never listed; AI tooling now finds novel chains cheaply — see [[AI-Accelerated Gadget Discovery]].
- **Module allowlists** are weaker than exact-name allowlists (a Python module allowlist still lets `builtins.eval` through).
- **Allowed classes still run their callbacks** — `__setstate__`, `__wakeup`, `readObject` on an allowed class is a permitted gadget.
- **Signatures are integrity, not safety** — they limit *who* can submit bytes; a leaked key (git history, env, CI log, image) turns a signed blob back into an unsigned one. Verification after deserialization is no protection.
- **"Weights-only" / option flags** are not full boundaries (Stanza reached `pickle.loads` under `weights_only=True`).
- **Scanner bypasses**: picklescan/modelscan denylists were bypassed repeatedly (JFrog, Sonatype) via extension trust, ZIP CRC/flag tampering, subclass imports.
- **Pre-.NET-4.5 ViewState** honoured an unencrypted payload if `__VIEWSTATEENCRYPTED` was simply removed.
## Real-world cases
| CVE / ID | Target | One line |
|---|---|---|
| CVE-2017-5638 / 9805 | Apache Struts | Equifax-era OGNL/XStream RCE |
| CVE-2025-20124 | Cisco ISE | CVSS 9.9, any admin incl. read-only |
| CVE-2025-53690 | Sitecore | ViewState via sample `machineKey` |
| CVE-2025-53770 | SharePoint "ToolShell" | Unauth ViewState webshell, mass-exploited |
| CVE-2025-59287 | WSUS | Unauth SOAP deserialization, in-the-wild |
| CVE-2025-5086 | DELMIA Apriso | WCF `NetDataContractSerializer`, KEV |
| CVE-2025-55182 | React/Next.js RSC | "Flight" protocol, CVSS 10.0 |
| CVE-2026-28326 | SolarWinds ARM | Hardcoded secret → .NET sink, SYSTEM |
| CVE-2026-129448 | Apache Roller | Pre-auth XML-RPC, KEV |
| CVE-2026-115731 | Puppet/OpenVox | `__ptype` report deserialization → `class_eval` → CA key; KEV 2026-11-17 |
| CVE-2026-54512 | jackson-databind (WildFly 35) | PTV allowlist bypass via generic type parameters |
| — | WildFly 32-35 IIOP | Pre-auth CORBA parameter deserialization |
| CVE-2026-115560 | PHP sessions "phpAfterShell" | Session serializer mismatch → RCE |
| CVE-2026-131754 | APCu Manager (WordPress) | Object injection, critical |
| CVE-2026-132751 | yt | `eval()` of a stored dataset attribute |
| CVE-2025-32444 | vLLM | Pickle over ZeroMQ, CVSS 10.0 |
| CVE-2026-126714 | PHP sessions "PHPAfterShell" | Spliced session file → `unserialize` |
| CVE-2022-1471 | SnakeYAML | Insecure-by-default YAML |
| — | Google DevSite ($90k) | Pickle cookie signed by its own secret |
## Prevention
1. **Don't deserialize untrusted data with a native object format.** Keep state server-side with an opaque identifier, or use JSON/MessagePack/Protobuf with an explicit schema. OWASP's first recommendation, and the only control under which no class was looked up at all in the DedSec lab.
2. **If a native format can't be removed, allowlist exact expected types at the deserializer**: Java `ObjectInputFilter`/JEP 290 with default-deny (`!*`); PHP `unserialize($x, ['allowed_classes' => [...]])` or `false`; a restricted Python `Unpickler` overriding `find_class` with exact `(module, name)` pairs; disable type binding (Jackson default typing off, Fastjson safeMode, Json.NET `TypeNameHandling.None`, PyYAML `safe_load`, Oj `:strict`). Audit the magic methods of every allowed class.
3. **Integrity-protect where the format is unavoidable**, but verify the signature *before* deserializing and keep keys secret and rotated; treat a leaked `machineKey`/`SECRET_KEY` as a deserialization finding.
4. **Isolate** deserialization in least-privilege, egress-restricted compartments; bind RPC/IPC to localhost and authenticate peers first; disable listeners the app doesn't need (IIOP) and weak certificate autosign; patch gadget-bearing libraries.
5. **For ML**, prefer `safetensors`, verify model provenance, and don't trust a file by extension — see [[Model Deserialization Attacks]].
## Tools
- **Payload generation / validation**: `ysoserial` (Java), `ysoserial.net` / `ysonet` (.NET), `phpggc` (PHP); `URLDNS` for Java verification; `r2pickledec`/`pickletools` to read pickles.
- **Discovery / static analysis**: GadgetInspector, Tabby, Crystallizer, ODDFuzz, FLASH (USENIX 2025), GadgetHunter, Gleipner benchmark; Serianalyzer, Find-Sec-Bugs.
- **Hunting / detection**: Mandiant HeySerial + CheckYoself; Burp deserialization scanners/extensions. **Scanners**: picklescan / modelscan / PickleBall for ML (with the bypass caveats above).
## Sub-pages
- [[Java Deserialization]] — `ObjectInputStream` and JVM marshallers; gadget sinks and the JDK 17+ shift.
- [[PHP Object Injection]] — `unserialize()`, `phar://`, POP chains, session-splice CVEs.
- [[Python Pickle Deserialization]] — `pickle.loads()` and its wrappers; the ML-model problem.
- [[NET Deserialization|.NET Deserialization]] — `BinaryFormatter`, type-binding JSON, ViewState/`machineKey`.
- [[Gadget Chains]] — POP anatomy, per-language entry points and sinks, discovery tooling.
- [[Polymorphic Deserialization]] — type-binding bugs in JSON/YAML/XML/BSON "data" formats.
- [[Model Deserialization Attacks]] — ML model/checkpoint/cache RCE and scanner bypasses (extra).
- [[AI-Accelerated Gadget Discovery]] — LLM-driven chain discovery breaking blocklist defences (extra).
## Sources
- [[raw/blog.checkpoint.com/sharepoint-zero-day-cve-2025-53770-actively-exploited-3783|SharePoint Zero-Day CVE-2025-53770]]
- [[raw/blog.ostorlab.co/puppet-server-deserialization-rce-cve-2026-115731-ostorlab-15875|Puppet Server deserialization RCE (CVE-2026-115731) - Ostorlab]]
- [[raw/blog.trailofbits.com/marshal-madness-a-brief-history-of-ruby-deserialization-exploits-3799|Marshal Madness: Ruby Deserialization Exploits]]
- [[raw/brandur.org/depickling-gadgets-and-chains-the-exploit-that-unraveled-equifax-4350|Depickling, Gadgets, and Chains: the Exploit that Unraveled Equifax]]
- [[raw/cheatsheetseries.owasp.org/owasp-deserialization-cheat-sheet-3818|OWASP Deserialization Cheat Sheet]]
- [[raw/chern0b.it/two-roads-to-rce-in-wildfly-pre-auth-corba-deserialization-and-json-pa-15864|Two roads to RCE in WildFly: pre-auth CORBA deserialization and JSON parser bypass]]
- [[raw/cloud.google.com/now-you-serial-now-you-don-t-systematically-hunting-for-deserializatio-2783|Systematically Hunting for Deserialization Exploits (Mandiant)]]
- [[raw/cloud.google.com/viewstate-deserialization-zero-day-in-sitecore-cve-2025-53690-4355|ViewState Deserialization Zero-Day in Sitecore]]
- [[raw/cobalt.io/the-anatomy-of-deserialization-attacks-3798|The Anatomy of Deserialization Attacks]]
- [[raw/corgea.com/apache-roller-cve-2026-129448-pre-auth-xml-rpc-deserialization-rce-exp-15527|Apache Roller CVE-2026-129448 pre-auth XML-RPC]]
- [[raw/dedsecops.com/insecure-deserialization-as-a-dast-finding-confirming-it-properly-15438|Insecure deserialization as a DAST finding: confirming it properly]]
- [[raw/docs.veracode.com/prevent-insecure-deserialization-attacks-veracode-4521|Prevent insecure deserialization attacks (Veracode)]]
- [[raw/github.com/apcu-manager-deserialization-of-untrusted-data-critical-15971|APCu Manager deserialization of untrusted data (critical)]]
- [[raw/greynoise.io/snakeyaml-deserialization-deep-dive-cve-2022-1471-3785|SnakeYAML Deserialization Deep Dive]]
- [[raw/invicti.com/insecure-deserialization-in-web-applications-3821|Insecure Deserialization in Web Applications]]
- [[raw/kaixuanli-ecnu.github.io/gadgethunter-neuro-symbolic-detection-of-java-deserialization-vulns-fs-15969|GadgetHunter: neuro-symbolic detection of Java deserialization vulns (FSE 2026)]]
- [[raw/learn.microsoft.com/binaryformatter-deserialization-security-guide-for-net-3807|BinaryFormatter Deserialization Security Guide for .NET]]
- [[raw/learn.snyk.io/insecure-deserialization-tutorial-and-examples-3816|Insecure Deserialization Tutorial and Examples]]
- [[raw/medium.com/bug-bounty-hunting-insecure-deserialization-4523|Bug Bounty Hunting: Insecure Deserialization]]
- [[raw/medium.com/deserialization-bugs-in-the-wild-3810|Deserialization Bugs in the Wild]]
- [[raw/netspi.com/phpaftershell-critical-php-vulnerabilities-cve-2026-115560-cve-2026-12-15870|phpAfterShell: Critical PHP Vulnerabilities (CVE-2026-115560 & CVE-2026-126714)]]
- [[raw/owasp.org/insecure-deserialization-owasp-2785|Insecure Deserialization | OWASP]]
- [[raw/portswigger.net/exploiting-insecure-deserialization-vulnerabilities-portswigger-2786|Exploiting Insecure Deserialization Vulnerabilities]]
- [[raw/portswigger.net/insecure-deserialization-web-security-academy-2717|Insecure deserialization | Web Security Academy]]
- [[raw/pwnatlas.app/insecure-deserialization-in-java-net-php-python-and-node-js-13755|Insecure deserialization in Java, .NET, PHP, Python and Node.js]]
- [[raw/r3vpwnx.medium.com/loading-a-dataset-should-not-run-code-15851|Loading a Dataset Should Not Run Code]]
- [[raw/research.eye.security/wsus-deserialization-exploit-in-the-wild-cve-2025-59287-4948|WSUS Deserialization Exploit in the Wild]]
- [[raw/simonkoeck.com/i-found-a-90k-remote-code-execution-vulnerability-in-google-12253|$90k RCE Vulnerability in Google]]
- [[raw/snyk.io/security-advisory-critical-rce-vulnerabilities-in-react-server-compone-8855|Critical RCE in React Server Components (CVE-2025-55182)]]
- [[raw/sonicwall.com/delmia-apriso-insecure-deserialization-exploited-in-the-wild-cve-2025-3801|DELMIA Apriso Insecure Deserialization (CVE-2025-5086)]]
- [[raw/thehackerish.com/insecure-deserialization-explained-with-examples-2782|Insecure Deserialization Explained with Examples]]
- [[raw/zerohunt.ai/puppet-enterprise-cve-2026-115731-deserialization-rce-15071|Puppet Enterprise CVE-2026-115731 deserialization RCE]]