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-09-01. Synthesized from 97 of 97 curated resources. Browse all 97 Deserialization resources →

The Essence of Deserialization Vulnerabilities

Deserialization, at its core, is the process of transforming serialized data—a sequence of bytes or a text representation—back into a complex object in memory. This mechanism is fundamental to many applications, enabling data persistence, inter-process communication, and state management across network boundaries. Languages like Java, Python, Ruby, and .NET have robust, often native, serialization capabilities that offer flexibility and efficiency for these tasks.

The inherent danger arises when an application deserializes data originating from untrusted or attacker-controlled sources without adequate validation or sanitization. This practice opens a critical attack vector, as attackers can craft malicious serialized payloads designed to exploit the deserialization process itself. Instead of simply representing data, these payloads can include executable code or instructions that manipulate application logic, leading to severe security consequences.

The OWASP Top Ten consistently ranks insecure deserialization as a high-risk vulnerability due to its potential to enable Remote Code Execution (RCE), privilege escalation, denial-of-service (DoS) attacks, and sensitive data exposure [1][2][3]. The attack surface is broad, spanning various programming languages and serialization formats, including JSON, XML, YAML, and language-specific binary formats like Java's ObjectInputStream or Python's pickle [4][2][5].

Core Mechanics of Exploitation

The foundation of most deserialization exploits lies in the deserializer's ability to instantiate objects and invoke methods—often including constructors, setters, and special "magic methods"—as part of the reconstruction process. When an attacker can control the serialized data, they can dictate which objects are instantiated and how their methods are invoked during deserialization. This is often achieved through a technique known as Property-Oriented Programming (POP) or gadget chaining.

Gadget Chains

A "gadget" is a piece of existing, benign code within an application's libraries or codebase that performs a specific operation. In the context of deserialization, attackers chain these gadgets together. The deserialization process initiates the chain by invoking a "kick-off" gadget, which then calls another gadget, and so on. This chain continues until it reaches a "sink" gadget—a method capable of executing arbitrary commands, accessing sensitive files, or achieving other malicious objectives [6][7][8].

The power of gadget chains lies in their ability to leverage legitimate code already present within the application's environment. Attackers do not need to inject new code directly; instead, they manipulate the flow of execution by controlling the data that existing code operates on. Tools like ysoserial for Java and ysoserial.net for .NET are designed to discover and generate payloads based on known gadget chains in common libraries [8][9].

Language-Specific Mechanisms

Notable Techniques and Attack Vectors

Beyond standard gadget chains, several specific techniques and attack vectors highlight the multifaceted nature of deserialization vulnerabilities:

"Kick-off" Gadgets in Ruby Marshal

In Ruby's Marshal.load, not all entry points into attacker-controlled code require explicit marshal_load, _load, or _load_data methods. Some "kick-off" gadgets are implicitly invoked. For instance, the hash method can be triggered when an object is used as a key in a deserialized Hash, and eql? can be called when hash collisions occur. These are often harder to patch as they stem from fundamental language behaviors [24].

Framework-Specific Gadgets

Frameworks can inadvertently introduce or expose gadgets. In Flask Ninja, the HttpBearer class's __call__ method could be abused by deserializing a crafted BearerAuth object, allowing an attacker to read sensitive headers [34]. Similarly, React Server Components (RSC) have had vulnerabilities stemming from unsafe deserialization of "Flight" protocol payloads, enabling RCE [35].

ViewState Deserialization in ASP.NET

ASP.NET's ViewState mechanism, used to persist page state, can be a target. If the machine key is compromised or validation is weak, attackers can craft malicious ViewState payloads, often serialized using LosFormatter or BinaryFormatter, to achieve RCE [31][36][37][32].

PHAR Deserialization in PHP

PHP Archives (PHAR) store metadata in a serialized format. When files are processed using the phar:// stream wrapper, this metadata is automatically deserialized. Attackers can leverage this to inject malicious objects into the PHAR's metadata, triggering magic methods during deserialization [18][19][22][23].

YAML Deserialization with PyYAML

Python's PyYAML library, when using yaml.load with the UnsafeLoader or equivalent, allows deserialization of arbitrary Python objects. This is particularly dangerous when used for configuration files or data parsing, as demonstrated in vulnerabilities found in frameworks like Docling [17][15][2].

Cloud-Native and ML Model Risks

The use of pickle in Python for serializing Machine Learning (ML) models poses significant supply chain risks. Malicious models uploaded to platforms like Hugging Face can contain embedded RCE payloads that execute upon model loading. Scanners like PickleScan aim to mitigate this but have themselves been found to have bypasses [38][39][40][15]. Tools like PickleBall offer safer deserialization solutions by statically analyzing library code to generate custom, safe loading policies [41].

Insecure Reflection via Deserialization

Reflection, the ability of a program to inspect and modify its own structure and behavior at runtime, is often leveraged during deserialization. If deserializers use reflection to instantiate or configure objects based on untrusted input, attackers can use reflection to load and execute arbitrary code [42][11].

Detection and Prevention

Effective mitigation of deserialization vulnerabilities requires a multi-layered approach, focusing on both preventing the deserialization of untrusted data and hardening the deserialization process itself.

Best Practices for Prevention

Detection Strategies

Tooling for Analysis and Exploitation

A variety of tools are essential for identifying, analyzing, and exploiting deserialization vulnerabilities:

Recent Developments and Trends

The landscape of deserialization vulnerabilities is constantly evolving:

Where to Go Deeper

For those seeking to deepen their understanding and practical skills in this area, the following resources are invaluable:

Sources cited in this guide

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