Sovra Recon·Glossary · Deserialization

Insecure Deserialization: Definition, Risks, and Protection

By Solan Barlet, co-founder of Sovra Recon
Updated October 29, 2026

In short

Serialization converts an object into a sequence of bytes for storage or transmission; deserialization reconstructs it. An insecure deserialization vulnerability occurs when an application reconstructs a user-supplied object using a native format (Java, PHP, Python pickle, .NET): the attacker can then manipulate the object’s data or even trigger remote code execution. It is referenced as CWE-502 and falls under the “Software and Data Integrity Failures” category in the OWASP Top 10 2021.

Why It’s Dangerous

Native serialization formats do not just carry data; they also specify which class to instantiate. During reconstruction, certain methods of these classes are executed automatically. By chaining together classes already present in the application or its libraries (a “gadget chain”), the attacker can execute commands without ever uploading any code.

Even without code execution, a modified object may be sufficient: for example, a role attribute set to “admin” in a serialized session object stored in a cookie.

Functions to Watch For

LanguageAffected functions
JavaObjectInputStream.readObject, as well as JSON or XML libraries configured to instantiate any class (polymorphic typing)
PHP`unserialize` applied to user data
Python`pickle.loads`, `yaml.load` with an insecure loader
.NETBinaryFormatter, which Microsoft states is dangerous and impossible to secure
RubyMarshal.load, insecure YAML loading

How to Protect Against It

  • Never deserialize user-supplied data using a native format; instead, use a pure data format such as JSON, which does not rely on automatic typing.
  • If this is unavoidable, sign the data (HMAC) and verify the signature before deserialization.
  • Restrict the allowed classes using a whitelist (deserialization filters in Java).
  • Keep libraries up to date: known exploit chains rely on them.

Frequently asked questions

Is JSON risk-free?

JSON describes only data, which eliminates most of the risk. It becomes dangerous again when a library is configured to instantiate the class specified in the document itself.

Sources

Find out where an attacker would get in.

Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.