Polymorphic Deserialization
The class of deserialization bugs in “data” formats — JSON, YAML, XML, BSON — that arises when the serializer lets the document name the concrete type to instantiate, re-introducing the object-injection problem people switched to JSON to avoid.
Why “safe” formats aren’t
After the 2015–16 Java wave, the common advice was to replace native serialization with JSON/XML. Black Hat “Friday the 13th JSON Attacks” (Muñoz & Mirosh) showed this is false when the library supports polymorphism: the requirements for RCE are (1) the library invokes methods on user-named types (constructors, setters, callbacks) and (2) a gadget space exists. The serialization format — binary, XML, JSON — is irrelevant. Data-only means the parser can construct nothing the schema did not ask for; the moment a $type/@type/!!python/object tag can pick a class, it is an object format again.
Mechanisms by stack
- Java JSON/XML: Jackson polymorphic typing (
enableDefaultTyping,@JsonTypeInfo) — CVE-2017-7525 and a long tail; FastjsonAutoTypereading@type→ class load → setter invocation, with JNDI sinks (JdbcRowSetImpl.setDataSourceName), patched/bypassed repeatedly below 1.2.83 / 2.0.45. XStream rebuilds arbitrary, even non-Serializable, types. - Jackson PTV generics bypass (CVE-2026-54512): with
BasicPolymorphicTypeValidatorcorrectly allowlistingjava.util.ArrayList, a type id ofjava.util.ArrayList<com.attacker.Gadget>takes the<branch that validates only the outer class, then the type factory loads and instantiates the inner one. Jackson’s separate hardcoded block-list (~100 classes) still stops the famous universal gadgets, so RCE needs an app-specific, non-blocklisted class on the classpath. Affects 2.18.2 (WildFly 35); fixed with recursive type-parameter validation (WildFly later ships 2.21.6) (WildFly two roads). - Puppet rich data (
__ptype):FromDataConverterparses an attacker-supplied__ptypein agent report events as a Puppet type; anObject[...]type with no registered implementation is built byRubyGenerator, whichclass_evals a class body containing theRubyMethodannotation. CVE-2026-115731, CISA KEV; fixed in Puppet Core 8.22.2/9.1.3 and PE 2023.8.13/2025.12.1/2026.0.1 (Ostorlab Puppet). - Java YAML: SnakeYAML instantiates arbitrary classes by default (CVE-2022-1471), “insecure by default” with a history of prior issues before the CVE.
- .NET JSON: Json.NET
TypeNameHandling != None,JavaScriptSerializertype resolvers, FastJSON — the type discriminator selects the class — see .NET Deserialization. - Ruby:
Ojdefault:objectmode instantiates arbitrary classes from JSON (httpx gem, CVE-2026-129784 / GHSA-jgqw-w3x2-9h6q), reachable when ActiveSupport supplies a chain; unsafe JSON/YAML (YAML.load) across the ecosystem. - Node / JS:
node-serializeencodes functions with the_$$ND_FUNC$$_marker inside otherwise ordinary JSON (so it does not look binary); seroval type-confusion in TanStack/Solid Start (CVE-2026-59940, CVE-2026-116580) where an unvalidated typed-array “buffer” child selects aTypedArrayconstructor overload and can invoke a registered callable; React Server Components “Flight” protocol (CVE-2025-55182). - BSON: MongoDB C# Driver and generic BSON type-restriction allow-list bypasses — an overly permissive type-check heuristic constructs unintended types.
Detection and prevention
- Look for
$type/@type/__type/__ptype/!!python/object/--- !ruby/object/_$$ND_FUNC$$_markers in request bodies; these are the tell that polymorphism is in play. - Disable type binding: Jackson default typing off, Fastjson
safeMode, Json.NETTypeNameHandling.None, SnakeYAMLSafeConstructor, PyYAMLsafe_load, Oj:strict. Where types are genuinely needed, bind to a concrete expected type or a strict allowlist. Validate the type of every child node (the seroval bugs were missing a runtime type check behind a TypeScript cast), including generic type parameters: an allowlist that inspects only the container is not an allowlist (CVE-2026-54512).
Related
- Insecure Deserialization
- Java Deserialization
- .NET Deserialization
- Gadget Chains
- Remote Code Execution
Sources
- Friday the 13th JSON Attacks (Black Hat) · original
- Puppet Server deserialization RCE (CVE-2026-115731) - Ostorlab · original
- Two roads to RCE in WildFly: pre-auth CORBA deserialization and JSON parser bypass · original
- Jackson deserialization exploit (3 gadgets) · original
- SnakeYAML Deserialization Deep Dive (CVE-2022-1471) · original
- Deep Dive into Fastjson Deserialization Vulnerabilities · original
- httpx RCE via Oj object-mode JSON deserialization · original
- GHSL-2026-200: Untrusted Seroval payloads · original
- Critical RCE in React Server Components (CVE-2025-55182) · original