Nullify

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Product Security Terms›
Insecure Deserialization

Product Security Terms

Insecure Deserialization

NT
Tim Thacker
November 27, 2026

What Is
Insecure Deserialization
?

Insecure deserialization is a vulnerability in which an application rebuilds objects from serialized data that an attacker can control, without checking that the result is safe. Because many deserializers create classes and run code while rebuilding objects, a crafted payload can change application data, crash the service or lead to remote code execution.

Also known as:

Deserialization of untrusted data, unsafe deserialization, CWE-502, PHP object injection

What Insecure Deserialization Means

Serialization turns an object in memory into bytes or text so it can be stored or sent, and deserialization rebuilds the object from that data. Insecure deserialization happens when an application rebuilds objects from data an attacker can control without making sure the result is safe. MITRE tracks it as CWE-502, Deserialization of Untrusted Data, and lists PHP object injection and unsafe unpickling in Python as names for the same problem. OWASP made it its own category, A8, in the 2017 OWASP Top 10.

How an Insecure Deserialization Attack Works

Native serialization formats do more than carry data. They record which classes to create, and many languages run code while an object is rebuilt, through constructors, magic methods or callbacks. An attacker who controls the serialized input can choose which classes get created and how their fields are set. By chaining classes that already exist in the application or its libraries, often called gadgets, the attacker turns the deserialization step into a way to run code. Python's documentation warns that malicious pickle data can run arbitrary code during unpickling, so a handler that calls pickle.loads() on a request body or cookie hands the attacker that ability. The same pattern applies to Java's ObjectInputStream.readObject(), PHP's unserialize() and .NET's BinaryFormatter.

Where Insecure Deserialization Shows Up

  • Session data and cookies. Applications that store serialized objects in cookies or hidden fields let users send them back modified.
  • Remote procedure call and messaging endpoints. XML-RPC, Java RMI, message queues and internal service APIs often pass serialized objects between systems.
  • JSON and XML libraries with type handling. Some parsers let the input name the class to create, which turns a plain data format into a native one.
  • Caches, job queues and ML model files. Data loaded from shared storage, including pickled model files, is only as trusted as everyone who can write to it.

Why Insecure Deserialization Is So Severe

MITRE lists remote code execution, changed application data and denial of service among the consequences of CWE-502. Because deserialization often happens before authentication or input validation runs, one crafted request can be enough. A successful attack runs with the privileges of the application, so the attacker can read secrets and environment variables, change data and move to internal services. That is why exploited deserialization flaws appear among remote code execution CVEs in widely deployed web platforms and frameworks.

How to Prevent Insecure Deserialization

  • Don't accept serialized objects from untrusted sources. Use a plain data format such as JSON and map it to objects in your own code.
  • Avoid formats that the vendor says can't be secured. Microsoft states that BinaryFormatter is dangerous and should not be used, and Python says never to unpickle untrusted data.
  • When you must deserialize native objects, restrict which classes can be created with an allowlist, such as Java serialization filters, and set limits on size and depth.
  • Sign or MAC serialized data you hand to clients, and check the signature before deserializing it.
  • Keep JSON and XML libraries patched and leave polymorphic type handling turned off unless you need it.

How Nullify Finds Insecure Deserialization

Nullify code analysis covers unsafe deserialization and deserialization of untrusted data (CWE-502). It flags unsafe use of native, JSON, XML and binary deserializers across languages. Its bottom-up analysis works backward from vulnerable operations, including serialization, to determine whether untrusted data can reach them, and its top-down analysis traces user input such as HTTP requests, API calls and file uploads through application logic. Nullify reviews every pull request and every commit on the default branch, so a new unsafe deserializer is caught before it ships. Explore Nullify Code Security.

Key Takeaways

  • Insecure deserialization means rebuilding objects from attacker-controlled data without making sure the result is safe.
  • MITRE tracks it as CWE-502, and OWASP listed it as its own category in the 2017 Top 10.
  • Native formats such as Java serialization, Python pickle, PHP unserialize and .NET BinaryFormatter can run code while objects are rebuilt, which often leads to remote code execution.
  • Using plain data formats, allowlisting classes and signing serialized data are the main defenses.

Read More About
Insecure Deserialization

Code Security

See Nullify in Action

Find untrusted data reaching unsafe deserializers before it ships.

Explore Code Security

Reduce your vulnerability backlog and lower your MTTR

The AI harness that finds, proves and fixes vulnerabilities across your codebase.

Book a demo