Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Alternative to validation: Use a SecurityManager.

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.  If such classes are poorly designed, such code could even call Runtime.exec() with an attacker-supplied argument.  Therefore, untrusted input to be deserialized should be validated to ensure that the serialized data contains only classes from a whitelist of expected classes.  This can be done by overloading the resolveClass() method of the ObjectInputStream class.  As an alternative to validation of the serialized data, a SecurityManager can be used to perform deserialization in a less-privileged context.

Non-Compliant Code Example

...