# Java Deserialization
> Insecure use of `ObjectInputStream.readObject()` (and JVM marshallers such as XStream, XMLEncoder, Hessian, Kryo, SnakeYAML, AMF stacks) on attacker-controlled bytes, where the class names in the stream decide which library callbacks run as the object graph is rebuilt.
## How it works
- **Stream format.** Java native serialization begins with the magic `AC ED 00 05` (`STREAM_MAGIC` + `STREAM_VERSION`); base64 `rO0AB`, gzip+base64 `H4sI`; the HTTP content type `application/x-java-serialized-object`. An object typically continues with `TC_OBJECT`/`TC_CLASSDESC`, giving the common prefix `rO0ABXNy`.
- **Where the risk lives.** `ObjectInputStream` reads the class name from the stream, loads that class from the classpath, and reconstructs it — invoking deserialization callbacks (`readObject`, `readResolve`) along the way. Collection types re-hash their keys while rebuilding, which is the implicit entry point for most gadget chains.
- **Impact depends on the classpath, not the sink.** The identical vulnerable line is a full compromise on one deployment and inert on another, because exploitability is a function of which library versions are present. A clean scan means only that no chain the scanner carried matched this classpath — weak evidence. See [[Gadget Chains]].
- **Gadget roles** (Gigamon's taxonomy around CVE-2017-9805): trigger, bypass (nested deserialization on an unfiltered stream), helper, and sink. The historically central JRE-internal sink is `TemplatesImpl`, which carries bytecode; outbound JNDI reference indirection is the other classic path.
## CORBA/IIOP: the forgotten listener
WildFly's full profiles open an IIOP listener (TCP 3528) that most web-focused testing never touches. In 32-35, the servant unmarshals EJB call parameters before the authentication check runs; the naming service also answers unauthenticated ([[raw/chern0b.it/two-roads-to-rce-in-wildfly-pre-auth-corba-deserialization-and-json-pa-15864|WildFly two roads]]).
- **Remote class loading is dead on modern JDKs.** `ORBUseCodebaseOnly` was left unset, but on JDK 17/21 codebase fetching requires a `SecurityManager`, which WildFly refuses to run with, so the no-gadget path does not work.
- **Local gadgets still work.** A `PriorityQueue` + BeanUtils comparator chain reaching `TemplatesImpl` runs a static initializer during unmarshalling. The client sees a CORBA marshalling exception *after* the code ran, so the error is not evidence of failure.
- **`serialVersionUID` must match.** CORBA rejects a gadget built against a different library version (BeanUtils 1.9.4 in 32-35).
- **Preconditions:** IIOP enabled and reachable, an EJB exported over IIOP with a suitable parameter type, a usable gadget library, and reflective access to the XML internals for `TemplatesImpl`.
- **Fix:** authenticate before deserializing parameters and force `ORBUseCodebaseOnly` on.
## Formats beyond ObjectInputStream
The JVM deserialization cheat sheet catalogues the same weakness across Java native, XMLEncoder, XStream, Kryo, Hessian/Burlap, Castor, json-io, Jackson, Fastjson, Genson, Jodd, the AMF stacks (Red5, Apache Flex BlazeDS, GraniteDS, WebORB) and YAML (SnakeYAML, jYAML, YamlBeans). XStream can rebuild non-`Serializable` classes, widening the exposure (Struts REST plugin, CVE-2017-9805). JSON/YAML type-binding variants are covered in [[Polymorphic Deserialization]].
## Modern JDK reality (17+)
Münch (OWASP Stuttgart 2024) and the Black Hat "Friday the 13th" research describe how the landscape shifted:
| Change | Effect |
|---|---|
| JPMS strong encapsulation (default JDK 16, enforced from LTS 17) | The JRE-internal sink becomes unreachable through reflection; many published chains stop working out of the box |
| Remote JNDI object-factory loading disabled (8u191 / 11.0.1) | The classic remote-codebase path is closed; attention moves to local object-factory abuse (Tomcat `BeanFactory`, hardened in 9.0.63 / 8.5.79 / 10.0.21) |
| Commons Collections 3.2.2 | Functor serialization disabled unless an unsafe system property is set |
Verification still works via `URLDNS` (a JRE-only DNS lookup, no gadget library required). Exploitation remains possible but resembles memory-corruption work: the standalone Xalan-J library sidesteps the module restriction, and JDBC-connection sinks (H2) were used against SolarWinds SEM (CVE-2024-0692). The Waratek and GadgetHunter/FLASH research notes that AI-assisted tooling now discovers novel chains cheaply, which undermines blocklist and denylist defences — see [[AI-Accelerated Gadget Discovery]].
## Detection
- Passively decode cookies, hidden fields, RMI/JMX/T3/IIOP ports, message queues and caches, looking for the magic prefix.
- Prefer `URLDNS` for a first confirmation; a response-identical handler can run code and still return a generic error, so an out-of-band signal is the reliable proof — see [[Out-of-Band Detection]].
- Engineer detections around the vulnerability (serialized or XML body reaching a deserializer, known gadget class families) rather than exploit artefacts; Gigamon showed that path- and keyword-based Struts rules were trivially evaded. Static tooling: GadgetInspector, Tabby, FLASH (USENIX 2025), Serianalyzer.
- **Gadgecy** (Kreyssig & Bartel, EASE 2024) checks a project's JARs and `pom.xml` for the dependency and JDK prerequisites of 46 known gadget chains (Ysoserial main and `newgadget` branches, open PRs, CVE-2022-36944). Only 4 chains (JRMPClient, JRMPListener, URLDNS, Jdk7u21) need nothing beyond the JDK. Prerequisites appeared in 10.76% of 2,211 Apache projects and 9.12% of 400 popular GitHub projects. It checks prerequisites only: exploitation still needs untrusted input reaching `ObjectInputStream.readObject()`.
## Notable cases
| CVE / ID | Product | Note |
|---|---|---|
| CVE-2015-4852 | WebLogic | Commons Collections wave; also CVE-2017-3248, CVE-2018-2628 (T3) |
| CVE-2016-1000027 | Spring-web `HttpInvokerServiceExporter` | Unfixed until Spring 6.0.0 |
| CVE-2017-9805 | Apache Struts REST plugin | XStream over `application/xml`; Equifax-adjacent class |
| CVE-2025-20124 | Cisco ISE | CVSS 9.9; exploitable by any admin account, incl. read-only |
| CVE-2025-24813 | Apache Tomcat | Session-file write + deserialization |
| CVE-2026-33439 | OpenAM | Pre-auth, bypassing the `WhitelistObjectInputStream` added after CVE-2021-35464 |
| CVE-2026-118636 | Apache MINA | `JavaNativeMessageDecoder`, no fix for 3.0 (migrate to 2.2.x) |
| CVE-2026-114938 | OpenJDK "Java4Shell" | Base64-decoder memory corruption; adjacent RCE class, not a gadget chain |
| CVE-2026-33728 | dd-trace-java | RMI endpoint without serialization filter |
| — (fixed after 41.0.0.Final, backported to 41.0.1) | WildFly 32-35 IIOP | `EjbCorbaServant` reads EJB method parameters before authenticating; pre-auth on TCP 3528 in full profiles ([[raw/chern0b.it/two-roads-to-rce-in-wildfly-pre-auth-corba-deserialization-and-json-pa-15864\|chern0b.it]]) |
Also: SAP jConnect (CVE-2025-42928), IBM webMethods (CVE-2025-36072), Gradle pre-auth daemon, Apache TomEE passivation files (CVE-2026-111241), AWS Advanced JDBC Wrapper cache poisoning (CVE-2026-14265), and the Oracle Coherence + Xalan blocklist-bypass chain (UltraRed).
- CVEs cover only 14 of the 46 known gadget chains (58.70% have no CVE at all), so CVE-driven SCA misses most gadget-bearing dependency versions ([[raw/dl.acm.org/analyzing-prerequisites-of-known-deserialization-vulnerabilities-on-ja-2778|EASE 2024]]).
## Prevention
- Do not deserialize untrusted data with native formats; prefer a data-only format with an explicit schema.
- Inventory platform listeners the profile enables (IIOP, RMI, JMX, T3) and disable or firewall the ones the app doesn't use; authenticate before any parameter unmarshalling.
- Where unavoidable, apply an allowlist serialization filter — `ObjectInputFilter` / JEP 290 (`jdk.serialFilter`), with `!*` as the default-deny. Allowlisting still runs allowed classes' callbacks, so audit those too.
- Keep gadget-bearing libraries patched, segment RMI/JMX ports, and treat a leaked signing key for a signed blob as a deserialization finding.
## Related
- [[Insecure Deserialization]]
- [[Gadget Chains]]
- [[Polymorphic Deserialization]]
- [[AI-Accelerated Gadget Discovery]]
- [[Remote Code Execution]]
- [[Log4Shell]]
## Sources
- [[raw/advisories.gitlab.com/cve-2026-33439-openam-pre-auth-rce-via-deserialization-3790|CVE-2026-33439: OpenAM Pre-Auth RCE via Deserialization]]
- [[raw/advisories.gitlab.com/cve-2026-33728-dd-trace-java-unsafe-deserialization-in-rmi-3789|CVE-2026-33728: dd-trace-java Unsafe Deserialization in RMI]]
- [[raw/baeldung.com/deserialization-vulnerabilities-in-java-3819|Deserialization Vulnerabilities in Java]]
- [[raw/blog.gigamon.com/exploiting-apache-struts-writing-better-detections-gigamon-4510|Exploiting Apache Struts: Writing Better Detections (Gigamon)]]
- [[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/dl.acm.org/analyzing-prerequisites-of-known-deserialization-vulnerabilities-on-ja-2778|Analyzing Prerequisites of Known Deserialization Vulnerabilities on Java Applications]]
- [[raw/github.com/aws-advanced-jdbc-wrapper-java-deserialization-rce-via-cache-poisoning-15074|AWS advanced JDBC wrapper deserialization RCE]]
- [[raw/github.com/cve-2025-24813-poc-apache-tomcat-java-deserialization-4947|CVE-2025-24813 PoC: Apache Tomcat Java Deserialization]]
- [[raw/github.com/gradle-deserialization-of-untrusted-java-objects-before-authentication-12497|Gradle deserialization before authentication]]
- [[raw/github.com/java-deserialization-cheat-sheet-3820|Java Deserialization Cheat Sheet]]
- [[raw/greynoise.io/snakeyaml-deserialization-deep-dive-cve-2022-1471-3785|SnakeYAML Deserialization Deep Dive (CVE-2022-1471)]]
- [[raw/klogixsecurity.com/java-deserialization-gadget-chains-explained-3793|Java Deserialization Gadget Chains Explained]]
- [[raw/lists.apache.org/apache-tomee-cve-2026-111241-code-execution-via-deserialized-passivati-14245|Apache TomEE CVE-2026-111241]]
- [[raw/owasp.org/exploiting-deserialization-in-recent-java-versions-owasp-stuttgart-4519|Exploiting deserialization in recent Java versions (OWASP Stuttgart)]]
- [[raw/sec.cloudapps.cisco.com/cisco-ise-insecure-java-deserialization-cve-2025-20124-4716|Cisco ISE Insecure Java Deserialization (CVE-2025-20124)]]
- [[raw/sentinelone.com/cve-2025-42928-sap-jconnect-rce-via-deserialization-3049|CVE-2025-42928: SAP jConnect RCE via Deserialization]]
- [[raw/spring.io/cve-2023-34040-spring-kafka-java-deserialization-4505|CVE-2023-34040: Spring-Kafka Java Deserialization]]
- [[raw/sprocketsecurity.com/insecure-reflection-practices-in-java-and-c-4352|Insecure Reflection Practices in Java and C#]]
- [[raw/support.contrastsecurity.com/spring-web-java-deserialization-cve-2016-1000027-contrast-4509|Spring-web Java Deserialization: CVE-2016-1000027]]
- [[raw/synacktiv.com/java-deserialization-tricks-synacktiv-4353|Java Deserialization Tricks - Synacktiv]]
- [[raw/ultrared.ai/the-classes-the-blocklist-forgot-chaining-oracle-coherence-and-xalan-i-13776|The classes the blocklist forgot]]
- [[raw/upwind.io/apache-mina-javanativemessagedecoder-unsafe-deserialization-rce-13431|Apache MINA JavaNativeMessageDecoder unsafe deserialization RCE]]
- [[raw/wiz.io/cve-2026-114938-rce-in-openjdk-everything-you-need-to-know-15165|CVE-2026-114938 RCE in OpenJDK]]
- [[raw/zeropath.com/ibm-webmethods-integration-cve-2025-36072-deserialization-rce-4712|IBM webMethods Integration CVE-2025-36072]]