Unsafe Deserialization
Untrusted serialized bytes should become validated data, not native objects with executable hooks and surprising behavior.
Frame the problem
Security starts with a concrete asset, attacker capability and trust crossing.
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.
| Prevent | Detect | Recover |
|---|---|---|
| Use simple data formats plus explicit schemas · Allowlist types and validate semantics · Cryptographically authenticate state that must round-trip through a client | Unexpected type names, schema failures and deserialization exceptions | Contain 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.
- 1Attacker starts with: A caller who can submit or modify serialized state.
- 2A native object deserializer constructs attacker-selected types or invokes hooks while rebuilding an object graph.
- 3The weak or missing boundary control is crossed: Untrusted bytes → in-memory object behavior
- 4Impact: Code execution, authorization bypass or corrupted application state.
- 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.
- • Use simple data formats plus explicit schemas
- • Allowlist types and validate semantics
- • Cryptographically authenticate state that must round-trip through a client
- • Unexpected type names, schema failures and deserialization exceptions
- • Contain the affected identity or component.
- • Scope access from audit evidence.
- • Fix the boundary and add a regression test.
- • Misconfiguration and new access paths can bypass the intended control.
- • A privileged insider or compromised control plane may still reach the asset.