Skip to content

Lesson 1 of 9 · 22m

Deserializers Are Interpreters

The core mental model: a deserializer does not merely load data — it executes a construction program supplied by whoever wrote the bytes.

The first thing to teach a new hire is this: a deserializer is not a parser with a fancy output type. In many runtimes it is an interpreter for a hidden programming language whose instructions are object types, constructor arguments, callbacks, and property writes. If attacker-controlled bytes reach that interpreter, the attacker is not just changing data — they are steering object creation inside your process.

The dangerous sentence

objects = deserialize(request.body)

That line looks harmless because the input is called data. But the useful question is not "what shape is the data?" It is "what code can run while the runtime reconstructs this value?" In Java, constructors, readObject, and reflection can run. In PHP, unserialize() can trigger autoloading and magic methods. In Python, pickle.loads() is explicitly documented as capable of executing arbitrary code.

Data is passive; behavior is not

A safe serialized value can be represented without invoking application behavior:

{"id": 42, "email": "analyst@sudosecurity.org", "admin": false}

A native object stream often encodes much more than fields. It can name a class, request a specific constructor path, trigger methods during reconstruction, and arrange references between objects. That means the wire format is effectively a small program. Treating it as passive data is the original sin.

The trust boundary matters more than the feature

The same parser can be acceptable in one place and catastrophic in another. Loading a pickle file written five minutes ago by your own batch job on the same host is very different from accepting a pickled model upload in a web request. Before judging a call site, establish:

  • Who can write these bytes?
  • Can they influence bytes indirectly through cache, queues, shared storage, or backups?
  • What privileges does the consuming process have?
  • Is integrity enforced before parsing, or only after damage is done?

A useful rule of thumb

If the format can name application classes or invoke reconstruction callbacks, assume it is executable until proven otherwise. JSON is not magically safe — unsafe type metadata handling can make JSON dangerous too — but plain JSON without automatic object materialization does not give the attacker a constructor invocation language.

Field notes

  • “We only deserialize internal messages” fails the first time a queue, cache, or object store becomes writable by a lower-trust workload.
  • Signing serialized blobs is strong only when verification happens before deserialization, using keys the attacker cannot influence.
  • Compression and encryption do not make a malicious object graph benign; they only obscure and transport it.
  • If documentation says a function can execute code, believe it. Do not build a security boundary on the hope that inputs will be polite.

Was this lesson helpful?

Sign in to rate