← Back to list

### **Risks of Insecure Deserialization in Java and Mitigation Measures**

Recently, I encountered the issue of **insecure deserialization in Java**, a risk that has been present since the early days of…

Aironman · 2025-03-12 12:03 · 1 claps · 3.0 min read
#serialization #j2ee #spring #hibernate #ysoserial
Open on Medium ↗

Risks of Insecure Deserialization in Java and Mitigation Measures

Recently, I encountered the issue of insecure deserialization in Java, a risk that has been present since the early days of ObjectInputStream. This vulnerability allows an attacker to intercept a serialized object (Serializable), modify it using tools like Burp Suite, decode it from Base64, and reinject it with malicious code using utilities like ysoserial. The fundamental problem lies in the fact that the security of deserialization falls on the developer, who must verify the origin and legitimacy of the object before processing it on the server.

However, an even greater challenge is the widespread use of frameworks that internally rely on ObjectInputStream, introducing security risks if not handled properly.

Affected Frameworks

Spring Framework

  • Spring provides ConfigurableObjectInputStream, an extension of ObjectInputStream that allows for the customization of class resolution through a ClassLoader.
  • There is documentation on GitHub detailing how to safely use ObjectInputStream in Spring. However, the responsibility for implementing security measures still falls on the developer.

Hibernate

  • Hibernate includes SerializationHelper, which uses ObjectInputStream to deserialize objects from an InputStream or a byte array.
  • While Hibernate controls class loading, it is still crucial to validate input and restrict deserialization to trusted objects.

Security Considerations

The use of ObjectInputStream in these frameworks does not automatically imply a vulnerability, but it does introduce risks that must be addressed with the following recommended practices:

Data Validation: Ensure that deserialized data comes from trusted sources. ✅ Use of Deserialization Filters: Implement filters to restrict which classes can be deserialized. ✅ Dependency Updates: Keep frameworks and libraries up to date to take advantage of security improvements.

The Industry Problem

Despite having tools like SonarQube, Snyk, or Trivy, many companies adopt a ”mark as not solvable” (Will not be solved) mentality, allowing critical vulnerabilities to reach production. The pressure to release software quickly, combined with code reviews that fail to detect these issues post-merge, exacerbates the situation. In practice:

  • If a developer is unaware of this vulnerability, they may introduce the risk unknowingly.
  • Teams often rely on automated tools without manually validating security findings.
  • The lack of a security culture and pressure for fast deliveries leads to the omission of proper measures.

This is not a problem exclusive to trivial applications; it occurs even in critical sectors like banking, energy, and healthcare, where insecure deserialization can lead to data leaks. Often, these incidents are hidden until the consequences are irreversible.

Other JDK Components Using ObjectInputStream

In addition to the mentioned frameworks, some standard Java packages use ObjectInputStream and may pose a risk:

  • java.beans.beancontext: Bean management in distributed environments.
  • javax.management: JMX management, widely used in enterprise environments.
  • javax.rmi.CORBA: Support for RMI over IIOP.
  • javax.swing.text: Text components in Swing.

Among them, javax.management is still in frequent use, while the others are being deprecated.

Vulnerabilities in Alternatives like Protocol Buffers (ProtoBuf) and Kryo

Although Protocol Buffers (ProtoBuf) and Kryo are popular serialization alternatives that offer better performance and a more efficient format, they are not immune to deserialization risks if not handled properly. ProtoBuf, for example, allows for more structured serialization and is used in microservices environments, but it is still important to validate schemas and data before deserializing. Kryo, used in distributed systems like Apache Spark, can also introduce vulnerabilities if not controlled over which classes are allowed for deserialization.

Both approaches can be more secure than ObjectInputStream if properly configured, but insecure deserialization remains a latent risk in both cases, especially when data comes from untrusted sources.

Documented Cases of Deserialization Vulnerabilities

Over the years, several organizations have experienced deserialization vulnerabilities in production. Notable cases include:

  • Uber: In 2016, it was identified that Uber’s microservices infrastructure was exposed to insecure deserialization, allowing attackers to execute malicious code.
  • GitHub: In 2018, GitHub faced a vulnerability related to insecure deserialization in its infrastructure, which forced the company to apply patches quickly.
  • LinkedIn: LinkedIn also had issues with insecure deserialization in its systems, leading to a thorough review of its security practices.
  • Reddit: Similarly, Reddit also acknowledged experiencing insecure deserialization incidents affecting systems that used serialization libraries like Kryo.
  • Twitter: Similarly, Twitter also recognized having suffered insecure deserialization incidents that affected its internal infrastructure.

These cases highlight the importance of implementing rigorous security measures, such as input validation, using filters, and restricting deserializable classes.

Insecure deserialization remains a real threat in the Java ecosystem. While modern tools and frameworks have tried to mitigate this issue, security still depends on the practices implemented by developers and software architects. It is crucial to foster a security culture in organizations and ensure that applications are designed with adequate protection mechanisms from the outset. Adopting more secure frameworks, rigorously validating data, and updating dependencies are key steps towards a more secure environment.

— -


메타데이터
post_id
cc13d1a7b1bf
slug
risks-of-insecure-deserialization-in-java-and-mitigation-measures-cc13d1a7b1bf
url
https://medium.com/@alonso-isidoro/risks-of-insecure-deserialization-in-java-and-mitigation-measures-cc13d1a7b1bf
canonical_url
https://medium.com/@alonso-isidoro/risks-of-insecure-deserialization-in-java-and-mitigation-measures-cc13d1a7b1bf
author_url
https://medium.com/@alonso-isidoro
status
ok
fetched_at
2026-06-26 06:47:43