Deserialization Vulnerability

Security · Java · Python
Definition

Deserialization is the process of converting stored or transmitted data (like JSON, YAML, or binary formats) back into objects your application can use. A deserialization vulnerability occurs when this process can be exploited to execute arbitrary code — by crafting malicious serialized data that, when deserialized, triggers dangerous operations like JNDI lookups, shell commands, or object instantiation chains.

Why deserialization leads to RCE

When your application deserializes data, it's reconstructing objects. If the deserialization library doesn't restrict what types of objects can be created, an attacker can craft data that causes the library to instantiate dangerous classes — classes that execute code in their constructors or magic methods.

Java is particularly susceptible because its native serialization supports arbitrary class instantiation. The concept of a "gadget chain" — a series of class instantiations that ultimately execute a shell command — has been discovered in Commons Collections, Spring, and dozens of other Java libraries.

Real deserialization CVEs

The fix

Never deserialize data from untrusted sources using native serialization or unrestricted YAML/object loaders. Use safe alternatives: yaml.safe_load() in Python, new Yaml(new SafeConstructor()) in Java, JSON instead of pickle, explicit type allowlists in Jackson.

Paste your manifest — get a fixed version with all CVEs patched in seconds.

Open PackageFix →

Free · No signup · No CLI · Runs in your browser

Common questions

What is the difference between serialization and deserialization?
Serialization converts an object to a storable/transmittable format (like JSON or binary). Deserialization is the reverse — converting stored data back into an object. The vulnerability is in deserialization, not serialization.
Is JSON deserialization safe?
JSON deserialization (parsing JSON into objects) is generally safe if you use a standard JSON library without polymorphic type handling enabled. The dangerous pattern is when JSON deserialization can instantiate arbitrary class types — which Jackson enables with 'default typing' enabled.
Which languages are most vulnerable to deserialization attacks?
Java has the most severe deserialization history due to its native serialization format supporting arbitrary class instantiation. Python (via pickle and unsafe YAML), PHP (via unserialize()), and Ruby (via Marshal) also have deserialization risks. Modern JSON-focused APIs are much safer.
How does PackageFix flag deserialization CVEs?
PackageFix flags specific package versions with known deserialization CVEs via the OSV database. Packages like SnakeYAML, Jackson Databind, and PyYAML are checked on every scan.

Related