Blog/Vulnerabilities

Insecure Deserialization: Why Rebuilding an Object Can Run Code

Deserializing untrusted data is closer to running an executable than to parsing a file. Here is why, how gadget chains work, and what actually fixes it.

CyberWatch AI26 November 2026 · 7 min read
A flat-pack furniture kit with parts and an instruction sheet laid out on a floor

Microsoft's own documentation for .NET contains a sentence that explains this entire vulnerability class better than most security papers. Describing the BinaryFormatter type, it offers an analogy: "assume that calling BinaryFormatter.Deserialize over a payload is the equivalent of interpreting that payload as a standalone executable and launching it." The same page states flatly that BinaryFormatter "is insecure and can't be made secure."

That is an unusually blunt thing for a platform vendor to say about its own widely used API, and it is the correct framing. Deserializing untrusted input is not like parsing a file. It is like running one.

What serialization actually does

Programs hold data as objects: structures in memory with fields, types and behavior attached. To store an object in a database, send it over a network or put it in a cache, the program converts it into a flat sequence of bytes. That is serialization. Rebuilding the object later is deserialization.

This is ordinary and necessary. Web session state, message queues, remote procedure calls, caching layers and configuration files all use it. The problem is not the idea. The problem is what some serialization formats include.

A plain data format records values: this field holds the number 7, that one holds the string "invoice". A rich object format records values and types: build me an instance of this class, set these fields on it, and here is a nested object of that other class. The second kind has to name classes, because otherwise it cannot rebuild the right object. And once the byte stream names classes, the sender of the byte stream chooses which code runs.

MITRE tracks the weakness as CWE-502, deserialization of untrusted data. In CISA's Known Exploited Vulnerabilities catalog, it is one of the most frequently tagged weakness types, which tells you this is not a theoretical concern raised by researchers. It is a mechanism attackers use.

How a gadget chain works

The step that confuses people is how naming a class leads to running a command, since no serialized object contains machine instructions.

Reconstructing an object is not inert. Depending on the language and the class, the runtime may call a constructor, a custom deserialization callback, a property setter, a comparison method when the object is placed in a sorted collection, or a cleanup method when it is garbage collected. Each of those is normal code written for a normal purpose.

An attacker reads through the classes available in the target application's dependencies looking for pieces whose side effects can be composed. One class invokes a method named in one of its fields when it is deserialized. Another holds a map that calls a comparison routine on its keys. A third wraps a transformation that resolves a class by name and calls it. Assembled in the right order, reconstructing that object graph ends with a process being launched. This assembly is a gadget chain, and it is called that because the attacker supplies no code at all. They supply a plan built from parts already installed.

The historical example that made this widely understood involved the Apache Commons Collections library. CVE-2015-7501 describes a long list of Red Hat JBoss products that allowed remote attackers to execute arbitrary commands via a crafted serialized Java object, related to the Commons Collections library. The library itself was doing what it was designed to do. The vulnerability was that products accepted serialized objects from the network.

Two consequences follow from this structure, and both are counterintuitive.

The vulnerable class is often not the exploited class. Patching a gadget does not fix the application, because another gadget will be found in another dependency. The fix has to be at the point where untrusted bytes are deserialized.

Adding a library can make an existing flaw exploitable. An application with a deserialization entry point and no usable gadget chain is exploitable the moment a dependency update introduces one. Nothing in the application changed.

Where it shows up in practice

Three places account for most real findings.

State the client sends back. If an application serializes state, hands it to the browser, and deserializes whatever comes back, the trust boundary is crossed on every request. ASP.NET ViewState is the classic example of this shape, and it is why the integrity key protecting it is security-critical rather than a performance detail.

Framework and endpoint handlers. CVE-2017-9805 is a clean illustration. The CVE record describes the REST plugin in Apache Struts, affecting 2.1.1 through 2.3.x before 2.3.34 and 2.5.x before 2.5.13, using an XStream instance for deserialization "without any type filtering, which can lead to Remote Code Execution when deserializing XML payloads." No type filtering is the whole bug. The endpoint accepted any class the sender named.

Server-to-server plumbing that was never meant to be reachable. Internal services often exchange serialized objects because the designers assumed only trusted peers would connect. CVE-2025-59287 in Windows Server Update Service is described in its CVE record as deserialization of untrusted data in WSUS allowing an unauthorized attacker to execute code over a network, scored 9.8 by Microsoft; CISA added it to the exploited catalog in October 2025. An update service is exactly the kind of component nobody thinks of as internet-facing until an inventory review finds some that are.

Why the same products come back

The on-premises SharePoint advisories of 2025 show the pattern that makes this class so stubborn. CVE-2025-53770 is described by Microsoft as deserialization of untrusted data in on-premises SharePoint Server allowing an unauthorized attacker to execute code over a network, with the record stating that Microsoft was aware an exploit existed in the wild. CISA's catalog entry notes that it is a patch bypass for CVE-2025-49704 and that the later update includes stronger protection. CISA's required action went further than patching: disconnect public-facing SharePoint Server instances that have reached end of life, including SharePoint Server 2013 and earlier.

Patch bypasses are the signature of an architectural problem. When the design moves serialized objects across a trust boundary, a fix that blocks one path leaves the others, and researchers find them.

What actually fixes it

In rough order of effectiveness.

  1. Do not deserialize untrusted input into rich objects. Accept a plain data format, validate it against a schema, and construct your own objects from the validated values. This removes the class of flaw rather than constraining it.
  2. Retire the dangerous serializers. Microsoft's guidance names BinaryFormatter, SoapFormatter, NetDataContractSerializer, LosFormatter and ObjectStateFormatter as performing unrestricted polymorphic deserialization, and points to XmlSerializer, DataContractSerializer and System.Text.Json as in-box serializers that can handle untrusted data safely. Starting in .NET 9 the in-box BinaryFormatter implementation throws exceptions on use, and the settings that previously re-enabled it have been removed. The equivalent in Python is to keep pickle away from any input that crosses a trust boundary.
  3. Allowlist the expected types. Where a rich format is unavoidable, restrict deserialization to the specific classes the application legitimately receives. An allowlist survives the discovery of new gadget chains; a denylist of known-bad class names does not.
  4. Turn off polymorphic type handling. Several JSON libraries can be configured to read a type name out of the document. That configuration reintroduces the vulnerability into a format that did not have it.
  5. Authenticate the payload. Sign serialized data with a key the attacker cannot obtain and reject anything whose signature does not verify. This is genuinely effective and fails in one specific way: default, shared or leaked keys. Treat the integrity key as a secret with a rotation plan.
  6. Contain the process. Deserialization endpoints should run with minimal privileges and no outbound internet access they do not need. This will not stop exploitation, but it changes what the attacker gets, which is the same argument made in our network security guide about segmentation.

Reading a deserialization advisory

When one lands, four questions decide your response.

  • Is the endpoint reachable without authentication? Unauthenticated deserialization in internet-facing software is the worst case in this class, and it attracts mass exploitation quickly.
  • Is the fix a filter or a design change? If the vendor describes added type restrictions, expect bypass research. If they describe removing deserialization from that path, the fix is likely durable.
  • Does the advisory reference an earlier CVE? A patch bypass means the product has an unresolved structural issue, and you should expect more advisories in the same component.
  • Does the required action go beyond patching? For SharePoint, CISA told agencies to disconnect end-of-life public-facing instances outright. When a national authority says disconnect rather than update, that is the instruction.

Because these flaws so often live in third-party components rather than your own code, dependency visibility does more work here than code review. Our guide to software supply chain security covers building that inventory, and our vulnerability management guide covers turning it into a work queue.

Checking a suspicious message instead of a payload? Paste the message or link into CyberWatch AI Scan for a free check.

The short version

Insecure deserialization happens when an application rebuilds objects from bytes it does not control. Because rich serialization formats name the classes to construct, and constructing a class can run code, the sender of the bytes effectively chooses the code. Attackers exploit it by chaining side effects of classes already present in the application, which is why patching individual libraries does not help and why the same products produce repeated advisories.

The durable fix is to stop accepting serialized objects across trust boundaries, and to use a plain data format with schema validation instead. Everything else is a constraint on an inherently dangerous operation. For the wider category this sits inside, see our explainer on remote code execution.

Frequently asked questions

What is serialization?

Converting a live object in a running program into a stream of bytes so it can be stored or sent somewhere, then rebuilt later. Deserialization is the reverse. Session state, caches, message queues and remote procedure calls all rely on it.

Why is deserializing untrusted data dangerous?

Because rebuilding an object can run code as a side effect, and formats that record which class to instantiate let the sender choose. The attacker is not supplying data to be parsed; they are supplying instructions about what objects to construct and therefore what code to execute.

What is a gadget chain?

A sequence of ordinary classes already present in the application's dependencies, strung together so that reconstructing them produces a useful effect such as running a command. The attacker writes no code of their own. They assemble existing behavior.

Is JSON safe from this?

JSON itself has no mechanism for naming a class, so plain JSON parsing is not vulnerable. The danger returns when a library is configured for polymorphic type handling, where a field in the document tells the parser which class to build.

Can I fix it by blocking dangerous class names?

A denylist is the weakest option because new gadget chains keep being found in new libraries. An allowlist of the specific types the application legitimately expects is far stronger, and not deserializing untrusted input at all is stronger still.

Does signing the serialized data help?

Yes, when done correctly. If the application only deserializes payloads carrying a valid signature made with a key the attacker does not have, they cannot submit their own object graph. This fails when the signing key is default, shared, guessable or disclosed by another flaw.

How do I find this in my own code?

Search for the deserialization entry points of your language and framework and trace where their input comes from. A call that reads from a request body, a cookie, a message queue or an uploaded file is the one that matters. Static analysis tools flag these reliably because the API names are well known.

Why do deserialization flaws keep appearing in the same products?

Because the vulnerable pattern is architectural rather than a single mistake. When a product's design passes serialized objects across a trust boundary, fixing one endpoint leaves the others, and patch bypasses are common. Several recent advisories have explicitly been bypasses of an earlier fix.

Sources

  1. CWE-502: Deserialization of Untrusted Data, MITRE
  2. Deserialization risks in use of BinaryFormatter and related types, Microsoft
  3. Deserialization Cheat Sheet, OWASP
  4. A08:2021 Software and Data Integrity Failures, OWASP
  5. CVE-2017-9805, CVE Program
  6. CVE-2025-53770, CVE Program
  7. Microsoft Releases Guidance on Exploitation of SharePoint Vulnerability CVE-2025-53770, US Cybersecurity and Infrastructure Security Agency
  8. Known Exploited Vulnerabilities Catalog, US Cybersecurity and Infrastructure Security Agency
Share this article
LinkedIn WhatsApp X
For organizations

Your people get these messages at work too.

CyberWatch AI sends your staff realistic practice attacks, trains the gaps it finds, and shows management exactly where the organization stands.