← Java / Spring · Contents

JAVA-028 / Advanced

Jackson default typing (enableDefaultTyping)

A08:2021 Software and Data Integrity Failures · CWE-502 Deserialization of Untrusted Data

Why is this a problem?

Adding @class to JSON permits arbitrary class instantiation.

How to fix it

java
ObjectMapper om = new ObjectMapper();   // Default typing OFF
// If polymorphism is required, specify allowed base types with PolymorphicTypeValidator

Further reading