public class WhiteListObjectInputStream
extends java.io.ObjectInputStream
An ObjectInputStream implementation that checks loaded classes
against a list of trusted packages or package prefixes.
Heavily inspired by and derived from org.apache.activemq.util.ClassLoadingAwareObjectInputStream in ActiveMQ as well as https://github.com/spring-projects/spring-amqp/commit/4150f107e60cac4a7735fcf7cb4c1889a0cbab6c.
ObjectInputStream| Modifier and Type | Field and Description |
|---|---|
static java.util.List<java.lang.String> |
DEFAULT_TRUSTED_PACKAGES |
baseWireHandle, PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, SC_BLOCK_DATA, SC_ENUM, SC_EXTERNALIZABLE, SC_SERIALIZABLE, SC_WRITE_METHOD, STREAM_MAGIC, STREAM_VERSION, SUBCLASS_IMPLEMENTATION_PERMISSION, SUBSTITUTION_PERMISSION, TC_ARRAY, TC_BASE, TC_BLOCKDATA, TC_BLOCKDATALONG, TC_CLASS, TC_CLASSDESC, TC_ENDBLOCKDATA, TC_ENUM, TC_EXCEPTION, TC_LONGSTRING, TC_MAX, TC_NULL, TC_OBJECT, TC_PROXYCLASSDESC, TC_REFERENCE, TC_RESET, TC_STRING| Constructor and Description |
|---|
WhiteListObjectInputStream(java.io.InputStream in)
Creates an ObjectInputStream that reads from the specified InputStream.
|
WhiteListObjectInputStream(java.io.InputStream in,
java.util.List<java.lang.String> trustedPackages)
Creates an ObjectInputStream that reads from the specified InputStream.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addTrustedPackage(java.lang.String trustedPackage) |
java.util.List<java.lang.String> |
getTrustedPackages() |
protected java.lang.Class<?> |
resolveClass(java.io.ObjectStreamClass desc)
Load the local class equivalent of the specified stream class
description.
|
protected java.lang.Class<?> |
resolveProxyClass(java.lang.String[] interfaces) |
void |
setTrustedPackages(java.util.List<java.lang.String> trustedPackages) |
boolean |
shouldTrustAllPackages() |
available, close, defaultReadObject, enableResolveObject, read, read, readBoolean, readByte, readChar, readClassDescriptor, readDouble, readFields, readFloat, readFully, readFully, readInt, readLine, readLong, readObject, readObjectOverride, readShort, readStreamHeader, readUnshared, readUnsignedByte, readUnsignedShort, readUTF, registerValidation, resolveObject, skipBytespublic static final java.util.List<java.lang.String> DEFAULT_TRUSTED_PACKAGES
public WhiteListObjectInputStream(java.io.InputStream in)
throws java.io.IOException
Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.
If a security manager is installed, this constructor will check for the "enableSubclassImplementation" SerializablePermission when invoked directly or indirectly by the constructor of a subclass which overrides the ObjectInputStream.readFields or ObjectInputStream.readUnshared methods.
in - input stream to read fromjava.io.IOException - if an I/O error occurs while reading stream headerjava.lang.SecurityException - if untrusted subclass illegally overrides
security-sensitive methodsjava.lang.NullPointerException - if in is nullObjectInputStream(),
ObjectInputStream.readFields()public WhiteListObjectInputStream(java.io.InputStream in,
java.util.List<java.lang.String> trustedPackages)
throws java.io.IOException
Creates an ObjectInputStream that reads from the specified InputStream. A serialization stream header is read from the stream and verified. This constructor will block until the corresponding ObjectOutputStream has written and flushed the header.
If a security manager is installed, this constructor will check for the "enableSubclassImplementation" SerializablePermission when invoked directly or indirectly by the constructor of a subclass which overrides the ObjectInputStream.readFields or ObjectInputStream.readUnshared methods.
in - input stream to read fromtrustedPackages - List of packages that are trusted. Classes in them
will be serialized.java.io.IOException - if an I/O error occurs while reading stream headerjava.lang.SecurityException - if untrusted subclass illegally overrides
security-sensitive methodsjava.lang.NullPointerException - if in is nullObjectInputStream(),
ObjectInputStream.readFields()protected java.lang.Class<?> resolveClass(java.io.ObjectStreamClass desc)
throws java.io.IOException,
java.lang.ClassNotFoundException
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 exception is thrown.
The default implementation of this method in
ObjectInputStream returns the result of calling
Class.forName(desc.getName(), false, loader)
where loader is determined as follows: if there is a
method on the current thread's stack whose declaring class was
defined by a user-defined class loader (and was not a generated to
implement reflective invocations), then loader is class
loader corresponding to the closest such method to the currently
executing frame; otherwise, loader is
null. 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.resolveClass in class java.io.ObjectInputStreamdesc - an instance of class ObjectStreamClassClass object corresponding to descjava.io.IOException - any of the usual Input/Output exceptions.java.lang.ClassNotFoundException - if class of a serialized object cannot
be found or isn't trusted.protected java.lang.Class<?> resolveProxyClass(java.lang.String[] interfaces)
throws java.io.IOException,
java.lang.ClassNotFoundException
resolveProxyClass in class java.io.ObjectInputStreamjava.io.IOExceptionjava.lang.ClassNotFoundExceptionpublic void addTrustedPackage(java.lang.String trustedPackage)
public java.util.List<java.lang.String> getTrustedPackages()
public void setTrustedPackages(java.util.List<java.lang.String> trustedPackages)
trustedPackages - list of packages trusted for deserialization
from ObjectMessage payloadspublic boolean shouldTrustAllPackages()
Copyright © 2022. All rights reserved.