Skip to main content
CriticalCodeOWASP A08:2021CWE-502

How to fix: Java ObjectInputStream Deserializes Request Data

An ObjectInputStream is constructed directly from request data and readObject() is called on it.

Why it matters

Java deserialization of untrusted data via readObject() is one of the most exploited server-side vulnerability classes in the JVM ecosystem, with public gadget chains (Commons Collections, and others) enabling remote code execution against many common libraries already on the classpath.

readObject() reconstructs arbitrary Java objects from the byte stream, invoking their readObject()/readResolve() methods along the way. If any class on the classpath has an exploitable method reachable from deserialization, an attacker-controlled stream can trigger it without needing any other vulnerability.

How to fix it

  1. 1Avoid Java native serialization for any data that crosses a trust boundary; use JSON or protobuf instead.
  2. 2If native deserialization is unavoidable, use a strict class allowlist via ObjectInputFilter (Java 9+) or a validating ObjectInputStream subclass.
  3. 3Keep dependencies patched and remove unused libraries that could contribute gadget chains.

Code examples

Restrict deserialization with ObjectInputFilter

Java
ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
ois.setObjectInputFilter(ObjectInputFilter.Config.createFilter("com.example.dto.*;!*"));
Object obj = ois.readObject();

References

Detected automatically by VulnRadar. The check id is code-deser-java-objectinputstream, stable across every scan so you can filter or diff on it.

See every code check

Questions

How severe is Java ObjectInputStream Deserializes Request Data?
VulnRadar rates this critical severity in the code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id code-deser-java-objectinputstream, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Java ObjectInputStream Deserializes Request Data map to?
It maps to CWE-502. In the OWASP Top 10 it falls under A08:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for java objectinputstream deserializes request data

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Java ObjectInputStream Deserializes Request Data | VulnRadar