Unsanitized user input in deserialization method

Description

It is bad practice to deserialize untrusted data, such as data that comes from params or cookies, without sufficient verification. Attackers can transfer payloads or malicious code via serialized data, and deserializing such data puts your application at risk.

Remediations

❌ Do not deserialize untrusted data

❌ Avoid XMLEncoder and XMLDecoder classes, as these are not recommended

✅ Prefer pure (data-only) and language-agnostic (de)serialization formats such as JSON. Avoiding language-specific (de)serialization formats reduces the risk of attackers manipulating the deserialization process for malicious purposes.

✅ Prefer (de)serialization methods that allow you to specify the object types that are allowed to be deserialized

❌ Never permit the (de)serialization of base object types (like Object).

Resources

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=java_lang_deserialization_of_user_input

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=java_lang_deserialization_of_user_input

Ready to take the next step? Learn more about Bearer Cloud.