Insecure Deserialization
Trusting a reconstructed object, an unsigned-blob fallback, and a type/gadget that runs on deserialize — why rebuilding objects from user data is dangerous.
- Track
- Web security
- Estimated time
- 25 min
- Level
- Intermediate
Before this lesson
Serialization turns an object into bytes to store or send; deserialization rebuilds it. Insecure deserialization is rebuilding an object from data the attacker controls and then trusting it — its fields, its signature, or even the class it names. At its worst, in languages with rich serialization, choosing the right type on the way back in leads straight to code execution.
These labs simulate serialization (base64 of JSON) and a gadget registry, so nothing real is executed and the lab engine is never touched. The behaviour — a reconstructed object trusted, a signature skipped, a gadget type triggering an action — mirrors the real bug.
What is the vulnerability?
- Trusting the rebuilt object. The session is a serialized
{user, role}; the server deserializes it and trustsrole. Flip it toadmin. - Unsigned-blob fallback. A signature is added, but verified only when present — strip it and the tampered object sails through.
- Gadget on deserialize. The deserializer builds the class named by a
__typefield and triggers its behaviour. A benignReportis fine; aCommandgadget performs a server action and leaks data.
Why does it happen?
The format is treated as if it were trusted internal state, but it made a round trip through the client. Signatures help only if they are mandatory. And deserializers that instantiate arbitrary types hand the attacker a construction primitive — the famous “gadget chains”.
How do you stop it?
Keep sensitive state on the server with only a random id at the client, or sign it and require a valid signature every time. Never deserialize untrusted bytes into behavioural types — parse plain data against a schema and build your own objects from the validated fields.
The three labs below walk this: forge a session object, strip a signature, and fire a gadget.
Labs
A trusted session object
SolvedEasyBrowser lab
Forge the session object to become admin.
Enter the labLockedSignature stripping
SolvedMediumBrowser lab
Forge the object without a signature to become admin.
Enter the labLockedA gadget chain
SolvedHardBrowser lab
Craft a Command gadget object that runs and leaks the server secret.
Enter the labLocked
