Course contentsShow
← Security
Lesson 1183 of 3,05224. Application Security - Input ValidationFree lesson

Deserialization Fundamentals and Attack Surface

Understanding serialization formats, deserialization processes, and why untrusted data deserialization creates vulnerabilities.

Deserialization Fundamentals and Attack Surface

What you'll learn: Why converting data back from storage formats can execute malicious code if you're not careful.

What Is Serialization and Deserialization?

Serialization is the process of converting complex objects (like classes, arrays, or data structures) into a simple format for storage or transmission—think JSON, XML, YAML, or binary formats. Deserialization is the reverse: reading that stored format and reconstructing the original object in memory.

Imagine packing a suitcase (serialization) for a trip and unpacking it at your destination (deserialization). If someone sneaks dangerous items into your suitcase while it's in transit, unpacking becomes hazardous.

Why Deserialization Is Dangerous

When applications deserialize data from untrusted sources (user uploads, network messages, cookies), they're essentially executing instructions embedded in that data. Many serialization formats preserve not just data, but also type information and object relationships.

An attacker can craft malicious serialized payloads that, when deserialized:

  • Instantiate dangerous classes
  • Trigger "magic methods" or constructors that execute code
  • Chain together seemingly harmless objects to achieve remote code execution

The application blindly trusts the serialized data's structure and recreates whatever objects are specified—opening the door to arbitrary code execution.

The Attack Surface

Deserialization vulnerabilities appear wherever applications deserialize external data:

  • REST API endpoints accepting serialized objects
  • Session cookies storing serialized user data
  • Message queues processing serialized jobs
  • Cache systems storing serialized results

The danger isn't the format itself—it's treating untrusted serialized data as safe instructions for object reconstruction.

Key Takeaway: Deserialization transforms external data into live objects; if that data comes from untrusted sources, attackers can inject malicious object graphs that execute code when reconstructed, making it a critical attack vector requiring strict input validation and safe deserialization practices.