Deserializing untrusted data can cause Java to create an object of an arbitrary attacker-specified class, provided that the class is available on the classpath specified for the JVM. Some classes have triggers that execute additional code when they are created in this manner, see SER13-J. Treat data to be deserialized as potentially malicious by default for more information. If such classes are poorly designed, such code could even invoke arbitrary methods, such as Runtime.exec()
with an attacker-supplied argument. Therefore, untrusted input to be deserialized should be validated to ensure that the serialized data contains only trusted classes, perhaps specified in a whitelist of trusted classes. This can be done by overloading the resolveClass()
method of the java.io.ObjectInputStream
class. As an alternative to validation of the serialized data, a java.lang.SecurityManager
can be used to perform deserialization in a less-privileged context.
...