Injectionunsafedeserialization

Unsafe Deserialization

Untrusted serialized bytes should become validated data, not native objects with executable hooks and surprising behavior.

Follow the failure

Frame the problem

Security starts with a concrete asset, attacker capability and trust crossing.

Asset
Application process integrity and the invariants of reconstructed data.
Attacker & capability
A caller who can submit or modify serialized state.
Trust boundary
Untrusted bytes → in-memory object behavior
AssetThreatAttack SurfaceTrust BoundaryVulnerabilityExploit PathImpactMitigationDefense in DepthResidual Risk

Why the system fails

A native object deserializer constructs attacker-selected types or invokes hooks while rebuilding an object graph.

The important question is not “what is Unsafe Deserialization?” but “which assumption let untrusted data or an over-scoped identity cross untrusted bytes → in-memory object behavior?” Trace the decision at the boundary, then constrain what can happen after the first control fails.

Design the control in layers

Start with the control closest to the interpretation or privilege boundary: Use simple data formats plus explicit schemas Then add a control that reduces blast radius and telemetry that proves the decision was enforced.

The resulting design is not labelled secure. Record the identified controls, the known failure paths, the remaining exposure, and the evidence you would need during an incident.

PreventDetectRecover
Use simple data formats plus explicit schemas · Allowlist types and validate semantics · Cryptographically authenticate state that must round-trip through a clientUnexpected type names, schema failures and deserialization exceptionsContain the affected identity or component, scope impact from audit evidence, and preserve a regression test.

Key points

  • Asset: Application process integrity and the invariants of reconstructed data.
  • Boundary: Untrusted bytes → in-memory object behavior
  • Primary control: Use simple data formats plus explicit schemas
  • Detection signal: Unexpected type names, schema failures and deserialization exceptions
  • Always ask what limits damage when the primary control fails.

Follow the attack

Safe conceptual simulation: capability → missing control → crossed boundary → asset impact.

  1. 1
    Attacker starts with: A caller who can submit or modify serialized state.
  2. 2
    A native object deserializer constructs attacker-selected types or invokes hooks while rebuilding an object graph.
  3. 3
    The weak or missing boundary control is crossed: Untrusted bytes → in-memory object behavior
  4. 4
    Impact: Code execution, authorization bypass or corrupted application state.
Blast radius
  • Code execution, authorization bypass or corrupted application state.

Defend, detect, recover

One prevention is a single point of security failure. Layer it and make failure observable.

Prevent
  • • Use simple data formats plus explicit schemas
  • • Allowlist types and validate semantics
  • • Cryptographically authenticate state that must round-trip through a client
Detect
  • • Unexpected type names, schema failures and deserialization exceptions
Respond & recover
  • • Contain the affected identity or component.
  • • Scope access from audit evidence.
  • • Fix the boundary and add a regression test.
Residual risk
  • • Misconfiguration and new access paths can bypass the intended control.
  • • A privileged insider or compromised control plane may still reach the asset.

Misconceptions

Claim
“A single use simple data formats plus explicit schemas control makes this safe.”
Reality
One control changes risk; it does not erase it. Design prevention, detection, recovery, and blast-radius limits together.