Java Deserialization Attack refers to a security control or process that protects systems and data from unauthorized access and threats.
Essential for preventing unauthorized system access, protecting sensitive data, and ensuring compliance with security regulations.
Used continuously across all systems to verify and manage access based on authorization policies and procedures.
Implements security measures and controls to identify, authenticate, and authorize users or systems before granting access to resources.
All organizations managing digital systems and data must implement controls to protect employees, customers, and business assets.
Apply best practices, regularly audit security controls, update policies, integrate with overall security strategy, and provide training.
A Java deserialization attack exploits the process of converting serialized byte streams back into Java objects. Attackers craft malicious serialized objects containing gadget chains that trigger arbitrary code execution when deserialized. The vulnerability exists because Java deserialization automatically invokes methods like readObject, readResolve, and finalize on reconstructed objects without validation.
Gadget chains are sequences of existing Java classes in the application classpath whose methods can be chained together during deserialization to achieve arbitrary code execution. Libraries like Apache Commons Collections, Spring Framework, and Apache Commons BeanUtils contain well-known gadget classes. Tools like ysoserial generate payloads that leverage these chains automatically.
Historically vulnerable frameworks include Apache Struts, Jenkins, JBoss, WebLogic, WebSphere, and Spring Framework. Any application using Java native serialization, RMI, JMX, or custom protocols with ObjectInputStream is potentially vulnerable. Even modern frameworks can be affected if they accept serialized Java objects from untrusted sources without proper filtering.
Detection methods include identifying ObjectInputStream usage in source code, monitoring for serialized Java object magic bytes (AC ED 00 05) in network traffic, using static analysis tools to trace untrusted data to deserialization sinks, and employing runtime agents that monitor deserialization activity. Penetration testers use ysoserial and similar tools to generate test payloads.
Primary defenses include avoiding Java native serialization entirely in favor of JSON or XML with strict schema validation. If serialization is required, implement ObjectInputFilter to allowlist expected classes, use look-ahead deserialization with class validation, keep libraries patched to remove known gadget classes, and apply network-level controls to restrict serialized object transmission.
ObjectInputFilter, introduced in Java 9 and backported to earlier versions, allows developers to define allowlists or denylists of classes permitted during deserialization. It can also restrict object graph depth, array sizes, and total bytes read. Process-wide filters provide baseline protection while stream-specific filters enable granular control for different deserialization contexts.
Successful Java deserialization attacks typically result in remote code execution with the privileges of the application server. Attackers can install backdoors, exfiltrate sensitive data, pivot to internal networks, deploy ransomware, or compromise entire infrastructure. The impact is often critical because application servers frequently run with elevated privileges and network access to backend systems.
Modern Java versions include built-in serialization filters, module system restrictions limiting reflective access, and deprecation warnings for the Serializable interface. Project Amber proposes record serialization with safer defaults. However, legacy codebases and third-party libraries still rely on traditional serialization, requiring ongoing vigilance and migration planning to safer alternatives.