What Is Insecure Deserialization? How to Prevent It
Insecure deserialization is when untrusted serialized data is turned into an object, letting the attacker change app behavior and run code. How it works, why it leads to RCE, signature and type allow list defense, detection with KAOS.
Quick answer: Insecure Deserialization is when an application turns externally supplied serialized data back into an object without trust, letting the attacker change the application's behavior and in some cases run code on the server. Serialization is turning an object into a storable or transmittable sequence of data; deserialization is the reverse. The problem is that the application blindly trusts the instructions inside that sequence when turning it back into an object. If the attacker crafts special data that triggers a dangerous chain when reconstructed, the result can go as far as remote code execution. The root fix: never deserialize data from an untrusted source directly; use signed, type restricted safe formats instead.
Insecure deserialization is one of the most destructive but least understood web flaws. It is invisible because it often runs quietly in the background, in session data, a cache or a message queue. It is on the OWASP Top 10, and a successful exploit usually ends in full server takeover. This article explains how insecure deserialization works and how to defend properly.
What serialization and deserialization are
When a program wants to write an object (say a user session) to disk or send it over the network, it turns it into a byte or text sequence; this is serialization. The other side takes that sequence and turns it back into an object; this is deserialization. It is a common, legitimate way to move data between applications.
The danger is that during deserialization some platforms reconstruct not only the data but also the behavior embedded in it. If the attacker crafts an object chain where certain methods trigger automatically on reconstruction, the application innocently runs that chain.
Why it is so dangerous
| Aspect | Classic injection | Insecure deserialization |
|---|---|---|
| Target | A query or command | The application's object graph |
| Visibility | Usually in an input field | Session, cookie, cache, queue |
| Typical impact | Data leak | Remote code execution |
| Detection | Signature scannable | Needs business context and chain knowledge |
The key point: the attacker often cannot even read the data, but can run commands via the chain triggered on reconstruction. This makes the flaw as destructive as command injection.
Where it appears
- Session and cookie data. If server side serialized session is given to the client and taken back, the attacker can alter it.
- Cache and message queues. Serialized objects moved between components.
- API and file import. Endpoints accepting complex objects.
- Hidden fields and tokens. Values carrying serialized state inside.
Proper defense
1. Do not deserialize untrusted data
This is the strongest defense. Externally supplied data must not be turned directly into an object. If unavoidable, use a simple, type restricted format that carries only the expected fields.
2. Add integrity verification
Serialized data given to the client must be signed with the server's secret key and the signature verified when taken back. So altered data is rejected. This is the same principle as the signature logic in JWT security.
3. Type allow list
If deserialization is unavoidable, allow only a limited set of permitted object types. Reconstructing unknown types must be prevented.
4. Least privilege and monitoring
The application account should run with limited privileges, and unexpected deserialization behavior should be monitored. This is part of managing security misconfiguration.
Deserialization flaw detection with KAOS
We detect insecure deserialization flaws with KAOS, DSET's AI powered autonomous security scanning engine. With its multi agent architecture KAOS discovers endpoints, cookies and tokens carrying serialized data, tests whether integrity verification exists, and when it can show that an altered payload is accepted and processed by the application it verifies this in a controlled way. It reports only proven findings; because this class needs business context, the machine discovers and verifies while the expert interprets the chain. KAOS works alongside the human expert and documents every finding with a working proof.
Frequently asked questions
Does insecure deserialization happen on every platform? Any environment that supports object serialization and deserializes untrusted data is at risk. The form of the risk varies by platform, but the principle is the same.
Does encrypting the data solve it? Encryption provides confidentiality but is not enough alone. What is really needed is integrity verification and never deserializing untrusted data.
How is this flaw noticed? Serialized looking values (cookies, tokens, hidden fields) are identified, and whether an altered payload is processed is tested in a controlled way.
Why is the impact so high? A successful exploit usually leads to remote code execution and full server takeover, so it is among the most critical findings.
Sources
- OWASP, Deserialization Cheat Sheet: https://cheatsheetseries.owasp.org
- OWASP, Insecure Deserialization: https://owasp.org
- MITRE, CWE 502: https://cwe.mitre.org/data/definitions/502.html
- PortSwigger Web Security Academy, Insecure deserialization: https://portswigger.net/web-security/deserialization
To detect insecure deserialization flaws in your application with a working proof from KAOS and our expert team, contact DSET. From our Ankara Hacettepe Teknokent laboratory we provide penetration testing and secure code review.
Kimliğinizi doğrulayın
Yetkilendirilmiş erişim alanı. Tüm giriş denemeleri kayıt altına alınır.