Insecure Deserialisation
The application rebuilds objects from serialised data that users can supply, so a crafted object graph can run code or change the application's behaviour when it is deserialised.
| Severity | Critical |
| CVSS 3.1 | 9.8 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H Open in the calculator |
| CVSS 4.0 | 9.3 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-502: Deserialization of Untrusted Data |
| OWASP Top 10 | A08:2025 Software or Data Integrity Failures |
| MITRE ATT&CK | T1190 Exploit Public-Facing Application, T1059 Command and Scripting Interpreter |
| Category | Insecure Deserialisation |
Description
The application accepts data in a native serialisation format, which can describe objects of arbitrary types, and deserialises it without restricting the types it creates. Examples include Java's ObjectInputStream and libraries such as XStream, .NET's BinaryFormatter or Json.NET with type name handling enabled, PHP's unserialize(), Python's pickle and unsafe YAML loaders, and Ruby's Marshal.
Creating an object can run code in its class, such as methods that are called automatically during deserialisation, so an attacker who chains such methods from libraries the application already loads, known as gadget chains, can make deserialisation itself run commands. Where a usable gadget chain exists, which is common in Java and .NET applications with typical libraries, the attacker can run arbitrary code on the server with the application's privileges, usually without authentication and often before any application-level checks run. Even without one, deserialisation can be abused to change object properties that the application trusts, such as roles or prices, or to exhaust memory and processor time.
The weakness typically shows itself on a test when serialised data is found in cookies, hidden fields, view state, API parameters or message queues, recognisable by markers such as rO0 (the Base64 form of a Java serialisation header) or PHP's O: object notation. It is then confirmed by sending payloads generated with tools such as ysoserial, ysoserial.net or PHPGGC that trigger a DNS lookup or a delay. Burp Suite reports serialised objects in HTTP messages, and extensions add active checks for known gadget chains.
Remediation
Stop deserialising untrusted data into arbitrary types:
- Do not deserialise untrusted data with native formats. Use a data-only format such as JSON, mapped to simple types defined by the application, and validate it against a schema.
- Disable polymorphic type handling in data formats: keep Json.NET's
TypeNameHandlingatNone, and avoid default typing in Jackson or restrict it to an allowlist of types. - Stop using
BinaryFormatter, which Microsoft states cannot be made secure. In PHP, usejson_decode()rather thanunserialize(); in Python, never unpickle untrusted data, and load YAML withyaml.safe_load(). - Where native deserialisation cannot yet be removed, sign the data with an HMAC and verify the signature before deserialising, and in Java apply a serialisation filter (
ObjectInputFilter) that allows only the expected classes. - Keep libraries up to date, remove unused libraries that provide gadgets, and run the application with the least privilege it needs.
Confirm the fix by repeating the original out-of-band payloads and checking that no interaction or deserialisation error results.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.