Insecure Deserialization

Back to glossary

What Is Insecure Deserialization?

Insecure deserialization is a vulnerability that occurs when an application deserializes untrusted data without validating it, allowing an attacker to manipulate the resulting object. Serialization converts an object into a storable or transmittable format, and deserialization rebuilds it. When the input is attacker-controlled, the rebuilt object can carry malicious state or trigger unintended code paths during reconstruction.

This flaw is dangerous because it can lead to remote code execution, one of the most severe outcomes among application security vulnerabilities. It held a place in the OWASP Top 10 for years and remains a high-impact issue in any system that accepts serialized objects from external sources, such as APIs, message queues, and session tokens.

How Deserialization Attacks Work

A deserialization vulnerability is exploited by feeding the application a crafted serialized payload that the deserializer processes as trusted input. The attack succeeds when reconstruction triggers behavior the developer never intended.

During deserialization, many languages automatically invoke methods on the object being rebuilt. An attacker chains together classes already present in the application or its dependencies so that the act of deserializing executes a sequence of calls ending in a dangerous operation. 

This often results in a code execution vulnerability, where the attacker runs arbitrary commands on the server. Because the malicious logic uses legitimate classes, the payload can slip past filters that only inspect surface-level input. This class of bug is uniquely dangerous because the vulnerability lives in the act of reconstruction itself, so parsing the input is enough to trigger it, with no further action required from the application. The same technique can also enable denial of service, authentication bypass, and data tampering depending on the available classes.

Common Languages and Frameworks Affected by Insecure Deserialization

Deserialization flaws appear across many ecosystems, but some are more exposed because their native serialization mechanisms invoke object methods automatically.

  • Java: A Java deserialization attack typically abuses the native ObjectInputStream and gadget chains in common libraries. This is the most documented variant.
  • Python: The pickle module executes arbitrary code during unpickling and should never process untrusted data.
  • PHP: The unserialize function can trigger magic methods that attackers chain into exploits.
  • .NET: Formatters like BinaryFormatter have well-known deserialization risks and are now deprecated.
  • Ruby: Marshal and YAML loading can instantiate arbitrary objects from untrusted input.

The common thread is that each mechanism reconstructs objects in a way that can invoke code, which is what makes untrusted input so dangerous.

Real-World Insecure Deserialization Exploits

A deserialization exploit has been at the root of several large breaches, usually because a public-facing endpoint accepted serialized data.

High-profile incidents have involved Java applications exposing serialized objects over HTTP, where attackers used gadget chains from widely used libraries to achieve remote code execution. The pattern recurs because serialized data often travels through trusted-looking channels, including cookies, API payloads, and inter-service messages, so it bypasses scrutiny that raw user input would receive. 

These flaws are also hard to spot in review, since the vulnerable line is often a single innocuous-looking deserialize call far from where the data enters the system. The framing in insecure deserialization OWASP guidance reflects this: the danger comes from assuming incoming objects are safe, whatever serialization format is in use. Strong vulnerability prioritization helps teams focus on deserialization points that are actually reachable from untrusted input, which is where exploitation happens.

How to Prevent Insecure Deserialization Vulnerabilities

Prevention starts with a simple principle: never deserialize data from an untrusted source if you can avoid it. When you must, constrain what can be reconstructed.

Effective controls include using data-only formats like JSON with strict schemas instead of native object serialization, applying allowlists that restrict which classes may be deserialized, and running deserialization in low-privilege contexts. Integrity checks such as signing serialized data prevent tampering in transit. Detecting these flaws early with static application security testing helps surface unsafe deserialization calls during development, before they reach a reachable endpoint. 

Runtime monitoring adds a second layer, flagging unexpected object types or class-loading behavior that can signal an attempt in progress. Keeping dependencies patched also matters, because many exploits rely on gadget chains in outdated libraries.

FAQs

Which programming languages are most commonly affected by deserialization vulnerabilities?

Java, Python, PHP, .NET, and Ruby are frequently affected because their native serialization can invoke object methods or execute code during reconstruction. Java is the most widely documented target.

Is insecure deserialization always exploitable when detected by a scanner?

No. Exploitability depends on whether the deserialization point processes untrusted input and whether usable gadget chains exist. Many flagged instances handle trusted data and are not practically exploitable.

How does insecure deserialization relate to remote code execution?

Deserializing attacker-controlled data can trigger chained method calls that end in arbitrary command execution. This makes remote code execution the most severe and most common impact of the vulnerability.

What is a gadget chain and how is it used in deserialization attacks?

A gadget chain is a sequence of existing classes whose methods, when invoked during deserialization, combine to perform a malicious action such as running a command. Attackers assemble them from available libraries.

How can input validation help prevent deserialization vulnerabilities?

Validation alone is limited, since malicious payloads use legitimate classes. Stronger measures include allowlisting permitted classes, using data-only formats, and signing serialized data to confirm integrity before any deserialization occurs.

Back to glossary
See Apiiro in action
Meet with our team of application security experts and learn how Apiiro is transforming the way modern applications and software supply chains are secured. Supporting the world’s brightest application security and development teams: