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 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 — 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 (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:

FormatHexBase64 begins
Java nativeAC ED 00 05rO0AB
Pickle proto 2/3/4/580 02/80 03/80 04 95/80 05 95gAJ/gAN/gASV/gAWV
PHP object / arrayO:5:"..." / a:1:{Tzo / YTo
.NET BinaryFormatter—AAEAAAD/////
ASP.NET ViewState—/wE
Ruby Marshal04 08BAh
Node node-serializemarker _$$ND_FUNC$$_ inside JSON—
gzip wrapper (any of the above)1F 8B 08H4sI

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); 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 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 (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 (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.
  • Encryption at rest is not trust. rConfig encrypted device passwords and then unserialized the decrypted value with no class list; the app itself encrypted whatever the user stored, so the ciphertext carried the gadget faithfully (CVE-2026-135692, advisory).
  • No key at all. Idunno.AntiCsrf ran ObjectStateFormatter without a MAC, unlike ViewState with machineKey; any non-empty cookie plus a gadget in the form field was enough (THN).
  • WAFs see only the planting request. For phpAfterShell the unserialize happens when PHP reads a spliced session file, and session data copied from a DB or queue never crosses the WAF (Cloudflare).
  • “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 / IDTargetOne line
CVE-2017-5638 / 9805Apache StrutsEquifax-era OGNL/XStream RCE
CVE-2025-20124Cisco ISECVSS 9.9, any admin incl. read-only
CVE-2025-53690SitecoreViewState via sample machineKey
CVE-2025-53770SharePoint “ToolShell”Unauth ViewState webshell, mass-exploited
CVE-2025-59287WSUSUnauth SOAP deserialization, in-the-wild
CVE-2025-5086DELMIA AprisoWCF NetDataContractSerializer, KEV
CVE-2025-55182React/Next.js RSC”Flight” protocol, CVSS 10.0
CVE-2026-28326SolarWinds ARMHardcoded secret → .NET sink, SYSTEM
CVE-2026-129448Apache RollerPre-auth XML-RPC, KEV
CVE-2026-115731Puppet/OpenVox__ptype report deserialization → class_eval → CA key; KEV 2026-11-17
CVE-2026-54512jackson-databind (WildFly 35)PTV allowlist bypass via generic type parameters
—WildFly 32-35 IIOPPre-auth CORBA parameter deserialization
CVE-2026-115560PHP sessions “phpAfterShell”Session serializer mismatch → RCE
CVE-2026-131754APCu Manager (WordPress)Object injection, critical
CVE-2026-132751yteval() of a stored dataset attribute
CVE-2025-32444vLLMPickle over ZeroMQ, CVSS 10.0
CVE-2026-126714PHP sessions “PHPAfterShell”Spliced session file → unserialize (SecurityWeek)
CVE-2026-131914Idunno.AntiCsrf (ASP.NET)Unkeyed ObjectStateFormatter on the CSRF form token; one pre-auth POST → w3wp.exe RCE, exploited in the wild
CVE-2026-135692rConfigEncryptStringCast unserializes decrypted fields; gadget in a device password fires on GET /api/devices
CVE-2026-131707ProfileGrid (WordPress)Object injection through 6.0.0.6
CVE-2026-129039Tribulant Newsletters (WordPress)Object injection through 4.18.2, critical
CVE-2026-131782Simple Shopping Cart (WordPress)Object injection through 5.3.3, critical
CVE-2022-1471SnakeYAMLInsecure-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

Sources