appsec.fyi

Deserialization — A Practical Guide

A curated AppSec resource library covering XSS, SQLi, SSRF, IDOR, RCE, XXE, OSINT, and more.

Deserialization: A Practical Guide

Curated and synthesized by . Last updated 2026-08-16. Synthesized from 96 of 96 curated resources. Browse all 96 Deserialization resources →

Problem Framing

Deserialization vulnerabilities represent a critical class of security weaknesses where an application processes serialized data without adequate validation or sanitization. This allows an attacker to inject crafted serialized objects, which, when deserialized, can lead to the execution of arbitrary code, data tampering, denial-of-service, or privilege escalation [1][2][3][4]. The OWASP Top Ten has consistently listed insecure deserialization as a significant risk, highlighting its potential for severe impact [5][4]. Unlike many other vulnerabilities, deserialization flaws often leverage existing application code and libraries (gadgets) to achieve malicious objectives, making them particularly potent and challenging to eradicate by simply removing specific "dangerous" classes [6][7][8][4]. This reliance on existing code allows attackers to construct sophisticated "gadget chains" that manipulate program flow during the deserialization process, ultimately leading to control over the target system [9][10].

The core of the problem lies in the trust placed upon serialized data. Applications often serialize objects to persist state, transmit data across networks, or facilitate inter-process communication. When this serialized data originates from or can be influenced by an untrusted source, and the deserialization process lacks robust validation, a pathway for exploitation emerges [1][2][3][4]. The deserialization mechanism itself, designed to reconstruct objects, can inadvertently execute attacker-controlled code during this reconstruction phase, often before application-level validation can occur [8][4]. This makes it difficult to mitigate by simply filtering at the application layer, as the danger is inherent in the deserialization process itself.

Core Mechanics

At its heart, deserialization is the process of converting a sequence of bytes or a structured text format back into an object in memory [11][12]. This process is native to many programming languages and libraries, including Java's ObjectInputStream.readObject() [10][13][3], Python's pickle.loads() [14][15][16], PHP's unserialize() [17][18][19][20][21], Ruby's Marshal.load() [22][23][24][25][26][9], and .NET's various serializers like BinaryFormatter [27][28][29][30][31].

When an application uses these deserialization functions with untrusted input, an attacker can craft a payload that, when processed, triggers a chain of method calls on existing classes within the application's classpath. These classes and their methods, often referred to as "gadgets," are legitimate code fragments that perform specific operations. When chained together through controlled object state during deserialization, they can achieve a malicious outcome, such as executing operating system commands [7][10][32][13].

The fundamental vulnerability arises from how deserialization functions, like Java's ObjectInputStream.readObject(), can invoke custom readObject(), writeObject(), finalize(), or other special "magic" methods within objects during the deserialization process [10][13]. Similarly, Python's pickle uses the __reduce__ method to execute arbitrary code [14][15][16], and PHP's unserialize() can trigger magic methods like __destruct() or __wakeup() [18][20][21][33]. Ruby's Marshal.load can initiate code execution through a series of method calls on deserialized objects, often involving classes from the standard library or gems [22][23][24][26][9].

Gadget chains exploit this by chaining together these methods, where the output of one method call becomes the input for another, ultimately leading to a "sink" method that performs a dangerous operation like Runtime.exec() or System.arraycopy() [6][10][13][8]. The availability and nature of these gadgets depend heavily on the language, the libraries available on the classpath, and the specific deserialization format used [32][13]. Tools like ysoserial for Java [32] and ysoserial.net for .NET [29] are designed to generate payloads based on known gadget chains.

Notable Techniques

The exploitation of deserialization vulnerabilities often revolves around identifying and chaining available gadgets. The techniques vary significantly based on the programming language and the specific serialization format.

Java Deserialization

Java deserialization has a long history of exploitation, primarily leveraging the java.io.Serializable interface and the ObjectInputStream.readObject() method. Gadget chains often utilize classes from common libraries like Apache Commons Collections, Spring Framework, and Groovy [10][32][13][34][3][4].

Python Deserialization

Python's pickle module is notoriously insecure, as its documentation explicitly warns against unpickling untrusted data [14][15][8][12][16][4].

PHP Deserialization

PHP's unserialize() function is the primary vector for object injection vulnerabilities.

Ruby Deserialization

Ruby's Marshal module and YAML.load are common targets for deserialization attacks.

.NET Deserialization

.NET applications present various deserialization vulnerabilities, often involving the BinaryFormatter and ViewState.

Detection and Prevention

The overarching principle for preventing deserialization vulnerabilities is to never deserialize untrusted data. If deserialization of untrusted data is unavoidable, robust validation, integrity checks, and strict type constraints are essential [2][45][3][4].

Detection Strategies

Prevention and Mitigation

Tooling

A variety of tools assist in the discovery, generation, and analysis of deserialization exploits and vulnerabilities.

Recent Developments

The landscape of deserialization vulnerabilities continues to evolve, with new chains and exploitation techniques being discovered regularly. Recent research highlights the persistent threat of these vulnerabilities across various languages and frameworks.

Where to Go Deeper

To further your understanding and hone your skills in combating deserialization vulnerabilities, explore the following resources:

Sources cited in this guide

  1. Insecure Deserialization Vulnerabilities — Acunetix — acunetix.com
  2. Insecure Deserialization: Risks, Examples, and Best Practices — promon.io
  3. Insecure Deserialization | OWASP — owasp.org
  4. Insecure deserialization | Web Security Academy — portswigger.net
  5. Prevent insecure deserialization attacks (Veracode) — docs.veracode.com
  6. Depickling, Gadgets, and Chains: The Exploit That Unraveled Equifax — brandur.org
  7. Deserialization Gadget Chain Definition — pentesterlab.com
  8. Insecure Deserialization: The Vulnerability That Gives Attackers RCE — aquilax.ai
  9. Ruby 2.x Universal RCE Deserialization Gadget Chain | elttam — elttam.com
  10. Java Deserialization Gadget Chains Explained — klogixsecurity.com
  11. Deserialization Attacks: How Exploiting Data Formats Can Break Security — firecompass.com
  12. Introduction to Deserialization Attacks — owlhacku.com
  13. Deserialization Vulnerabilities in Java — baeldung.com
  14. PayloadsAllTheThings: Insecure Deserialization Python — github.com
  15. Breaking Pickle: RCE Through Python Deserialization — medium.com
  16. Reversing Pickles with r2pickledec — blog.doyensec.com
  17. picoCTF Super Serial Writeup: PHP Object Injection Explained Clearly — medium.com
  18. The Anatomy of Deserialization Attacks — cobalt.io
  19. PayloadsAllTheThings - PHP Deserialization Payloads — github.com
  20. What is PHP Object Injection? An In-Depth Guide — jetpack.com
  21. PHP Object Injection Research — sonarsource.com
  22. Ruby 4.0 Universal RCE Deserialization Gadget Chain - elttam — elttam.com
  23. PayloadsAllTheThings - Ruby Deserialization Payloads — github.com
  24. Marshal Madness: A Brief History of Ruby Deserialization Exploits — blog.trailofbits.com
  25. Unsafe Deserialization in Ruby | SecureFlag — knowledge-base.secureflag.com
  26. Lab: Exploiting Ruby Deserialization Using a Documented Gadget Chain | PortSwigger — portswigger.net
  27. PayloadsAllTheThings: Insecure Deserialization DotNET — github.com
  28. Deep Dive into .NET ViewState Deserialization — swapneildash.medium.com
  29. ysoserial.net: Deserialization Payload Generator for .NET — github.com
  30. .NET Deserialization Cheat Sheet — github.com
  31. BinaryFormatter Deserialization Security Guide for .NET — learn.microsoft.com
  32. ysoserial: Java Deserialization Payload Generator — github.com
  33. Exploiting Insecure Deserialization Vulnerabilities | PortSwigger — portswigger.net
  34. PayloadsAllTheThings - Java Deserialization Payloads — github.com
  35. An In-depth Study of Java Deserialization RCE Exploits — dl.acm.org
  36. Jackson deserialization vulnerability exploit (3 gadgets, GitHub) — github.com
  37. Java Deserialization Tricks - Synacktiv — synacktiv.com
  38. Analyzing Prerequisites of Known Deserialization Vulnerabilities on Java Applications — dl.acm.org
  39. Java Deserialization Cheat Sheet — github.com
  40. Apache Struts2 Code Execution Exploit (Infopercept) — infopercept.com
  41. Exploiting Apache Struts: Writing Better Detections (Gigamon) — blog.gigamon.com
  42. SnakeYAML Deserialization Deep Dive (CVE-2022-1471) — greynoise.io
  43. Docling RCE via PyYAML (CVE-2026-24009) — oligo.security
  44. PickleBall: Secure Deserialization of Pickle-based ML Models — arxiv.org
  45. OWASP Deserialization Cheat Sheet — cheatsheetseries.owasp.org
  46. Insecure DeserializationWeb ChallengesPart 1 — medium.com
  47. The Art of Hide and Seek: Pickle-Based Model Supply Chain Poisoning — arxiv.org
  48. PyTorch Users at Risk: 3 Zero-Day PickleScan Vulnerabilities — jfrog.com
  49. Pickle Deserialization in ML Pipelines: The RCE That Won't Go Away — afine.com
  50. Exposing 4 Critical Vulnerabilities in Python Picklescan — sonatype.com
  51. How to Exploit PHAR Deserialization Vulnerability — pentest-tools.com
  52. Exploiting PHP Deserialization with POP Chains — medium.com
  53. CVE-2025-34153: Hyland OnBase RCE via Deserialization — sentinelone.com
  54. ViewState Deserialization Zero-Day in Sitecore (CVE-2025-53690) — cloud.google.com
  55. SharePoint Zero-Day CVE-2025-53770 Actively Exploited — blog.checkpoint.com
  56. Basic .Net deserialization ObjectDataProvider gadget (HackTricks) — book.hacktricks.xyz
  57. .NET JSON.NET Deserialization RCE — invicti.com
  58. Insecure Deserialization in Web Applications — invicti.com
  59. CVE-2025-12305: Shiyi-blog RCE via Deserialization — sentinelone.com
  60. Insecure Deserialization Tutorial and Examples — learn.snyk.io
  61. Now You Serial, Now You Don't — Systematically Hunting for Deserialization Exploits | Google Cloud — cloud.google.com
  62. Security Advisory: Critical RCE Vulnerabilities in React Server Components (CVE-2025-55182) — snyk.io
  63. Precise and Effective Gadget Chain Mining through Deserialization-Guided Call Graph Construction (USENIX Security 2025) — usenix.org
  64. Automated Discovery of Deserialization Gadget Chains (Black Hat) — i.blackhat.com
  65. Gleipner: A Benchmark for Gadget Chain Detection in Java Deserialization Vulnerabilities — dl.acm.org
  66. Deserialization Gadget Chains in Android: An In-Depth Study — arxiv.org
  67. Leaking internal headers in Flask Ninja with deserialization — eval.blog
  68. WSUS Deserialization Exploit in the Wild (CVE-2025-59287) — research.eye.security
  69. IBM webMethods Integration CVE-2025-36072: Deserialization RCE — zeropath.com
  70. Ruby Vulnerabilities: Exploiting Open, Send, and Deserialization — bishopfox.com
  71. DELMIA Apriso Insecure Deserialization Exploited in the Wild (CVE-2025-5086) — sonicwall.com
  72. CVE-2026-25769: Wazuh Critical RCE via Unsafe Deserialization — resecurity.com
  73. CVE-2025-42928: SAP jConnect RCE via Deserialization — sentinelone.com
📚 This guide is synthesized from the full text of resources curated in the Deserialization library, and refreshed as new material is added.