The Novee Gym is open for business at Black Hat Europe

Book a meeting

The Novee Gym is open for business at Black Hat Europe

Book a meeting

Glossary › Insecure Deserialization

Insecure Deserialization

Explore Article +

Key Takeaways

  • Insecure deserialization happens when an application rebuilds objects from untrusted data without checking what those objects will do.
  • It is tracked as CWE-502 and falls under A08:2025 Software or Data Integrity Failures in the OWASP Top 10.
  • Attackers chain code already in the application’s libraries, turning one deserialization call into a remote code execution vulnerability.
  • The safest fix is to stop deserializing native objects from untrusted sources.

What Is Insecure Deserialization?

Insecure deserialization is a flaw where an application turns untrusted serialized data back into live objects without validating it. Serialization converts an object into bytes or text for storage or transport, and deserialization rebuilds it.

Many native formats describe more than data. They name the classes to create and the state to give them, so whoever controls the stream controls which objects the application builds. MITRE tracks this as CWE-502, Deserialization of Untrusted Data.

How Deserialization Vulnerabilities Lead to Remote Code Execution

A deserialization attack reuses code the application already trusts.

The attacker first finds serialized objects crossing a trust boundary, such as cookies, tokens, or API parameters. Next, they build a payload from “gadgets,” classes on the classpath whose methods run automatically during deserialization. Linked together, each method passes attacker-controlled values to the next until the last one runs a system command.

The chain fires during deserialization, before any business logic checks the result, with the application’s privileges. Like other exploit chains, it turns harmless-looking behaviors into one critical outcome, much as trusted input became code execution in the Gemini CLI RCE vulnerability.

Where Insecure Deserialization Appears Most Often

Java

Java deserialization is the best-known case, because ObjectInputStream.readObject() instantiates any serializable class on the classpath. Chris Frohoff and Gabriel Lawrence presented the problem at AppSec California 2015, and Frohoff released ysoserial to generate payloads from gadget chains in libraries such as Apache Commons Collections.

PHP, Python and .NET

PHP’s unserialize() can trigger magic methods, and the PHP manual warns never to pass it untrusted input. Python’s pickle can execute arbitrary code while unpickling. Microsoft says .NET’s BinaryFormatter “can’t be made secure,” and since .NET 9 it throws an exception on use.

Why Insecure Deserialization Is Hard to Detect With Automated Tools

Signature-based scanners match known payloads and responses, which fits deserialization poorly. A working exploit depends on which libraries the target loads, so a generic payload fails against an application with different gadgets even when the flaw is present. Serialized objects are often compressed or wrapped in formats scanners never decode. Exploitation is also frequently blind, which many DAST tools handle inconsistently.

How to Prevent Insecure Deserialization

  • Avoid native serialization for untrusted data. Use JSON mapped to simple data transfer objects.
  • Enforce strict allowlists. In Java, serialization filters (ObjectInputFilter) can reject unexpected classes before they load.
  • Sign serialized data. Refuse any object that fails an HMAC or signature check.
  • Trim dependencies. Fewer libraries mean fewer gadgets.

New dependencies can reintroduce the flaw, which is why modern application penetration testing treats it as an ongoing check. Novee runs continuous AI pentesting across web apps and APIs, reasoning about inputs and workflows like an attacker. Three independent agents validate each finding with proof of exploitability, and Agentic Remediation retests to confirm the fix holds.

FAQ

Yes. Attackers can spot serialized objects by their byte patterns or encoding in cookies, parameters, and headers, then send payloads built from gadget chains in popular libraries. They do not need source code, only a guess about which libraries the application loads, which they refine through error messages and out-of-band callbacks.

No. Java gets the most attention, but CWE-502 lists PHP, Python, Ruby, and JavaScript among affected languages, and .NET has its own history with BinaryFormatter. Any language whose native serializer can instantiate arbitrary types during reconstruction is at risk when it processes untrusted input.

A gadget chain is a sequence of existing classes whose methods run automatically while an object is deserialized. An attacker links them so each method passes controlled values to the next, ending in a dangerous call such as command execution. The chain uses only code already present in the application or its libraries.

Partly. A WAF can block requests matching known serialized-object signatures or published payloads. But attackers can encode or wrap payloads, and many applications legitimately send serialized data, so strict rules break functionality. A WAF buys time, but fixing how the application handles untrusted input is the real control.

Ysoserial is a proof-of-concept tool released by Chris Frohoff that generates serialized Java payloads. It wraps a chosen command inside a known gadget chain, such as ones from Apache Commons Collections, and outputs the object. Testers send it to an endpoint to confirm whether the application deserializes untrusted data unsafely.