Top Description Fields Constructors Methods
ch.qos.logback.core.net

public Class HardenedObjectInputStream

extends ObjectInputStream
Class Inheritance
Imports
java.io.IOException, .InputStream, .InvalidClassException, .ObjectInputFilter, .ObjectInputStream, .ObjectStreamClass, java.util.ArrayList, .List

HardenedObjectInputStream restricts the set of classes that can be deserialized to a set of explicitly whitelisted classes. This prevents certain type of attacks from being successful.

It is assumed that classes in the "java.lang" and "java.util" packages are always authorized.

Author
Ceki Gülcü
Since
1.2.0

Field Summary

Modifier and TypeField and Description
private static final int
private static final int
private static final String[]
private final List<String>

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected void
addToWhitelist(List<String> additionalAuthorizedClasses)

private void
private boolean
isWhitelisted(String incomingClassName)

protected Class<?>
resolveClass(ObjectStreamClass
an instance of class ObjectStreamClass
anObjectStreamClass
)

Overrides java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description.
Inherited from java.io.ObjectInputStream:
availableclosedefaultReadObjectenableResolveObjectgetObjectInputFilterreadreadreadBooleanreadBytereadCharreadClassDescriptorreadDoublereadFieldsreadFloatreadFullyreadFullyreadIntreadLinereadLongreadObjectreadObjectOverridereadShortreadStreamHeaderreadUnsharedreadUnsignedBytereadUnsignedShortreadUTFregisterValidationresolveObjectresolveProxyClasssetObjectInputFilterskipBytes

Field Detail

ARRAY_LIMITback to summary
private static final int ARRAY_LIMIT
DEPTH_LIMITback to summary
private static final int DEPTH_LIMIT
JAVA_PACKAGESback to summary
private static final String[] JAVA_PACKAGES
whitelistedClassNamesback to summary
private final List<String> whitelistedClassNames

Constructor Detail

HardenedObjectInputStreamback to summary
public HardenedObjectInputStream(InputStream in, String[] whitelist) throws IOException
HardenedObjectInputStreamback to summary
public HardenedObjectInputStream(InputStream in, List<String> whitelist) throws IOException

Method Detail

addToWhitelistback to summary
protected void addToWhitelist(List<String> additionalAuthorizedClasses)
initObjectFilterback to summary
private void initObjectFilter()
isWhitelistedback to summary
private boolean isWhitelisted(String incomingClassName)
resolveClassback to summary
protected Class<?> resolveClass(ObjectStreamClass anObjectStreamClass) throws IOException, ClassNotFoundException

Overrides java.io.ObjectInputStream.resolveClass.

Doc from java.io.ObjectInputStream.resolveClass.

Load the local class equivalent of the specified stream class description. Subclasses may implement this method to allow classes to be fetched from an alternate source.

The corresponding method in ObjectOutputStream is annotateClass. This method will be invoked only once for each unique class in the stream. This method can be implemented by subclasses to use an alternate loading mechanism but must return a Class object. Once returned, if the class is not an array class, its serialVersionUID is compared to the serialVersionUID of the serialized class, and if there is a mismatch, the deserialization fails and an InvalidClassException is thrown.

The default implementation of this method in ObjectInputStream returns the result of calling

Class.forName(desc.getName(), false, loader)
Class.forName(desc.getName(), false, loader)
where loader is the first class loader on the current thread's stack (starting from the currently executing method) that is neither the platform class loader nor its ancestor; otherwise, loader is the platform class loader. If this call results in a ClassNotFoundException and the name of the passed ObjectStreamClass instance is the Java language keyword for a primitive type or void, then the Class object representing that primitive type or void will be returned (e.g., an ObjectStreamClass with the name "int" will be resolved to Integer.TYPE). Otherwise, the ClassNotFoundException will be thrown to the caller of this method.
Parameters
anObjectStreamClass:ObjectStreamClass

an instance of class ObjectStreamClass

Returns:Class<?>

a Class object corresponding to desc

Annotations
@Override
Exceptions
IOException:
any of the usual Input/Output exceptions.
ClassNotFoundException:
if class of a serialized object cannot be found.