Use this when applications deserialize untrusted data.
Insecure Deserialization
Insecure deserialization turns untrusted serialized data back into objects in a way that lets attackers run code or change logic. Avoid native deserialization of user input; use JSON with strict schemas.
1. Insecure deserialization can lead to remote code execution.
2. Never deserialize untrusted data with native formats.
3. Use JSON + schemas.
4. Sign data if needed.
5. Patch libraries.
untrusted data → safe parser/validation → objects
Context & applicabilityCommon mistakes · platform/version boundaries
- Deserialising cookies, ViewState or cache data without signing (ASP.NET ViewState MAC disabled).
- Allow-listing classes too broadly.
- Gadget chains in common libraries (Commons Collections) present on the classpath.
- Assuming JSON is always safe — polymorphic type handling (Jackson
enableDefaultTyping) brings the same risk.
Operational reference
Fast context before you go deeper.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Insecure deserialization can lead to code execution.
- Avoid native deserialization of untrusted input.
- Use JSON with strict schemas.
- Code review: pickle/ObjectInputStream/unserialize on untrusted data — unsafe deserialization
- Use JSON with schema validation — safe formats
- Dependency scan for gadget libraries — known issues
ReferenceWhy it matters1 section · depth on demand
Defences
- Do not deserialize untrusted data with native formats (Java serialization, Python pickle, PHP unserialize, .NET BinaryFormatter).
- Use simple data formats (JSON) with schema validation.
- If unavoidable: sign the data (HMAC) and verify before deserializing, and restrict allowed classes.
Many remote code execution vulnerabilities in Java applications came from deserialization gadget chains.
ReferenceHow it works1 section · depth on demand
In depth
Insecure deserialisation occurs when an application converts untrusted serialised data back into objects using formats that can instantiate arbitrary types — Java serialisation, .NET BinaryFormatter, Python pickle, PHP unserialize, unsafe YAML loaders. Attackers can trigger code execution through gadget chains in available libraries.
Prevention:
| Practice | Detail |
|---|---|
| Do not deserialise untrusted data with native object formats | Use JSON with explicit schemas |
| Use safe loaders | yaml.safe_load, not yaml.load |
| Allow-list classes | Java serialisation filters (JEP 290) |
| Sign/verify serialised data | If it must round-trip through clients |
| Remove dangerous APIs | BinaryFormatter is obsolete in .NET |
| Keep libraries patched | Gadget chains often live in common libraries |
ReferenceImportant terms & boundaries1 section · depth on demand
Risky APIs
| Language | Dangerous | Safer |
|---|---|---|
| Java | ObjectInputStream.readObject | JSON with fixed types; deserialization filters (JEP 290) |
| PHP | unserialize() on user data | json_decode() |
| Python | pickle.loads, yaml.load | json, yaml.safe_load |
| .NET | BinaryFormatter | System.Text.Json |
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Web Security → Insecure Deserialization. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%