A simple diagram of the Insecure Deserialization risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for Insecure Deserialization
Testing path: establish a baseline, make one controlled change, and verify the effect.

Issue

Serialization converts data or objects into a form that can be stored or sent. Deserialization reads that form and reconstructs data or objects from it. Applications use these processes for files, messages, cookies, API requests, caches, and other data.

A deserialization weakness occurs when an application accepts data an attacker can influence and reconstructs objects from it without adequate controls. The risk depends on the format, the deserializer, the available classes or types, and what the application does with the result. Some object types run custom code during reconstruction or later use; others may let an attacker change security-sensitive fields. These behaviors can cause unintended actions or corrupt application logic. CWE-502, OWASP Deserialization Cheat Sheet

Common causes include:

  • Passing client-controlled cookies, request fields, uploaded files, or messages to a native object deserializer.
  • Letting input select arbitrary classes or types during reconstruction.
  • Deserializing domain objects that contain sensitive fields or behavior, instead of simple data-transfer objects.
  • Trusting serialized data because it is encoded, stored in a database, or was originally generated by the application. Those properties do not prove that it has not been changed.
  • Using JSON or XML with unsafe type metadata, custom object construction, or object-merging behavior. These formats are not automatically safe when configured to instantiate arbitrary types or when the parsed data is used unsafely. OWASP Deserialization Cheat Sheet

Examples

Request: a browser sends a client-side state cookie to an application

GET /account/preferences HTTP/1.1
Host: app.example.test
Cookie: state=eyJ0aGVtZSI6ImxpZ2h0IiwibGFuZ3VhZ2UiOiJlbiJ9

The cookie value resembles Base64-encoded JSON containing display preferences. That observation does not prove a vulnerability. The server may parse it as plain data, verify a signature, ignore it, or handle it in another way. Testing must establish how the application processes the value.

Benign tampering check

In a test account, change a preference such as "theme":"light" to "theme":"dark" and send the request in staging. A safe design might reject the modified value if it is signed, or accept the preference while continuing to enforce authorization on the server. This check can show whether a value is mutable and used; it does not prove access-control bypass or code execution.

Python anti-pattern

# Unsafe if payload can be controlled or tampered with by an attacker.
value = pickle.loads(payload)

Python’s pickle format can execute code during unpickling, so do not use it for untrusted input. For simple client-supplied data, use a data format such as JSON and validate the parsed fields and their types. Python pickle documentation

Impact

Possible outcomes include denial of service, unauthorized changes to application state, access-control errors, information disclosure, or code execution. These are possible consequences, not guaranteed results of finding a serialized value. Their likelihood and severity depend on whether an attacker can supply or alter the input, what types the application can construct, and what behavior those types or the application trigger. CWE-502

For example, code execution generally requires a path from attacker-controlled input to a deserializer and a usable class or behavior that causes code to run. A field such as role=admin being accepted is evidence of a possible authorization flaw, but it does not by itself prove account takeover. An encoded cookie or a deserialization error is also only an indicator; neither confirms that an attacker can reach a harmful behavior.

Testing

1. Trace attacker-influenced data to object reconstruction

Identify encoded cookies, files, or messages and review how the application parses them. Confirm whether a native object deserializer receives data a client can change.

Example: A Base64 value alone is not a vulnerability. Find the actual deserialization path and trust boundary.

GET /account/preferences HTTP/1.1
Host: app.example.test
Cookie: state=TEST_SERIALIZED_VALUE

2. Check integrity and sensitive state

Change a harmless preference in a test value and compare the server’s response and stored state. Review how sensitive fields and type choices are protected.

Example: A changed preference being accepted can be legitimate. It does not prove code execution or access-control bypass.

GET /account/preferences HTTP/1.1
Host: app.example.test
Cookie: state=MODIFIED_TEST_VALUE

3. Review serializer restrictions and failure handling

Inspect type allowlists, resource limits, signature verification, and error behavior for each input path. Use relevant platform documentation for the actual serializer.

Example: A parser error is not proof of object reconstruction. An integrity check on one cookie does not cover every deserialization path.

False positives and limits: A Base64 value, Java serialization header, or suspicious field name does not establish that the server deserializes the value. A parser exception does not show code execution. A signature check that rejects a modified token is useful evidence of tamper detection, but it does not prove that every deserialization path is protected or that authorization is correct.

Mitigation

Primary fixes

  • Avoid deserializing untrusted object formats. Use a data-only format and parse into simple, explicitly defined structures. JSON parsing is not a complete fix if the application enables attacker-controlled type metadata or merges input into sensitive objects.
  • Use narrow input models. Accept only the fields needed for the operation, with explicit type, length, and range checks. Keep authorization decisions and sensitive state on the server; do not trust client-provided roles, ownership, or permissions.
  • If a legacy format must remain, restrict it. For Java, configure an ObjectInputFilter before reading objects, allow only the classes required by that specific use case, and set limits on graph depth, references, array lengths, and stream size. Oracle cautions that deserialization of untrusted data should be avoided and that filters must be configured for the relevant use case. Oracle ObjectInputFilter documentation
  • Replace unsafe legacy serializers. Microsoft states that .NET BinaryFormatter.Deserialize is never safe with untrusted input and that BinaryFormatter cannot be made secure through configuration; migrate to a supported alternative. Microsoft BinaryFormatter security guide
  • For signed client state, verify authenticity before deserialization. Use a secure message authentication code (MAC), such as HMAC, and compare it safely before parsing or reconstructing the protected value. Keep keys secret and support rotation. Signing detects unauthorized changes; it does not by itself prevent replay, replace authorization checks, or make an unsafe deserializer safe in every context. PHP’s manual recommends validating externally stored serialized data with hash_hmac() if it must be unserialized. PHP unserialize() documentation

Additional defenses

  • Limit request and message sizes, and impose time and resource limits to reduce denial-of-service risk.
  • Run the deserialization component with only the permissions it needs, and keep dependencies patched. Isolation can limit consequences, but it does not remove the underlying flaw.
  • Log rejected inputs and unexpected deserialization activity without recording secrets or full sensitive payloads.

Retest each input path: confirm that tampered data is rejected or treated only as validated plain data, disallowed types are blocked where filters apply, resource limits work, and sensitive operations still enforce server-side authorization. A passing test for one cookie or endpoint does not establish that every deserialization path is safe.