

For the global filter, you can set a JVM argument or set it in code. You can set such a filter as a global JVM filter or individually per stream. In addition, you can create block and allow lists based on a pattern to limit the classes you want to get deserialized. You can place limits on array sizes, graph depth, total references and stream size. This was introduced in Java 9 with the implementation of JEP 290. To address deserialization vulnerabilities in Java, it is possible to set serialization filters. This means that we are still vulnerable to gadget chains in normal POJOs regardless of records. More importantly, we still use the readObject() function to deserialize. Doing so wrongly can create gadgets that can play a role in a deserialization gadget chain. Nevertheless, we can debate if you should put any logic in a record at all. If for any reason you put validation logic in the constructor of a Record, we now know this will logic will be applied, For Records, there is no magic involved when recreating the object when deserializing. Read my previous blog post for more information.

This means that any logic triggered by the constructor will not occur when deserializing an ordinary Java object. For ordinary Java objects, this is not the case, and the framework heavily depends on reflection. In contrast to normal POJOs when deserializing a Record, the constructor is used to recreate the object.
#JAVA 16 NEW FEATURES UPGRADE#
However, since many developers prefer to upgrade only to LTS versions, it makes sense to discuss Records in the context of serialization now Java 17 is fully released. Records were introduced in Java 14 as a preview feature and became a fully released feature in Java 16. JEP 415 (Java Enhancement Proposal) Context-Specific Deserialization Filters. In the blog post, I will look at three main Java 17 features: But how do the new features impact this problem, and can we prevent deserialization vulnerabilities better using these features? Recently, Java 17 - the new LTS version - was released.
#JAVA 16 NEW FEATURES CODE#
Insecure deserialization can lead to arbitrary code executions if a gadget chain is created from your classpath classes. The serialization framework is so deeply embedded inside Java that knowing how dangerous some implementation can be is important. In December 2020, I wrote the article Serialization and deserialization in Java: explaining the Java deserialize vulnerability about the problems Java has with its custom serialization implementation.
