Objects are read back with Java's built-in serialization

tx0/java:native-deserializationstrictwarningsecurity, cwe-502

What it finds

new ObjectInputStream(input).readObject() recreates whatever object graph the bytes describe, running code of the classes involved while it does. Bytes from outside the program can name classes on the class path whose deserialization does harm, a well-known route to remote code execution (CWE-502). A data format such as JSON with explicit types, or an ObjectInputFilter, keeps that under control.

Reported is every ObjectInputStream and XMLDecoder created; whether its input is trusted cannot be seen from the code, so the rule is in the strict tier. A stream is left alone when the code that makes it sets an ObjectInputFilter, when it is an anonymous subclass, which may check classes in resolveClass, and inside classes that extend ObjectInputStream themselves.

From the rule's source, native_deserialization.rs.

Example from the rule's tests
import java.io.InputStream;import java.io.ObjectInputStream; class Loader {  Object load(InputStream in) throws Exception {    try (ObjectInputStream s = new ObjectInputStream(in)) {tx0 reports: this stream recreates any object graph      return s.readObject();    }  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/java:native-deserialization" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:native-deserialization] reason="..."

tx0 explain tx0/java:native-deserialization shows the same in the terminal. Found a false positive? Report it.