public class ValidatingObjectInputStream extends ObjectInputStream
Reading must be done using the safeRead
methods which sets validation parameters before
reading. Any attempt to use read
methods will be blocked.
See OWASP.
ObjectInputStream.GetField
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
Modifier and Type | Method and Description |
---|---|
static ValidatingObjectInputStream |
build(InputStream in)
Create a new input stream for reading objects.
|
protected Class<?> |
resolveClass(ObjectStreamClass desc) |
protected Object |
resolveObject(Object obj) |
long |
safeReadLong()
Update validation parameters and read the next long from the stream.
|
<T> T |
safeReadObject(Class<T> type,
Collection<Class<?>> safeClasses,
int maxObjects,
long maxBytes)
Update validation parameters and read the next object from the stream.
|
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, resolveProxyClass, skipBytes
mark, markSupported, read, reset, skip
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
read, skip
public static ValidatingObjectInputStream build(InputStream in) throws IOException
safeReadObject(Class, Collection, int, long)
which updates the validation parameters
before reading.in
- stream to read fromIOException
- on I/O errorpublic <T> T safeReadObject(Class<T> type, Collection<Class<?>> safeClasses, int maxObjects, long maxBytes) throws ClassNotFoundException, IOException, ClassCastException
T
- type of returned objecttype
- Type to return. This type will be whitelisted. If the stored object may be of a
subclass to this type then the permitted subclasses must be included in
safeClasses
.safeClasses
- Collection of whitelisted classes. This must include all classes used within the
stored object.maxObjects
- Maximum number of objects to read. This must be large enough to permit valid use,
especially for collection objects.maxBytes
- Maximum number of bytes to read from the stream. This must be large enough to
permit valid use, especially for collection objects.IOException
- on I/O errorClassNotFoundException
- if the class of the stored object can't be foundClassCastException
- if the object is not of the specified typepublic long safeReadLong() throws IOException
IOException
- on I/O errorprotected Object resolveObject(Object obj) throws IOException
resolveObject
in class ObjectInputStream
IOException
protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException
resolveClass
in class ObjectInputStream
IOException
ClassNotFoundException
Copyright © 2019. All rights reserved.