19
19
import java .io .ByteArrayOutputStream ;
20
20
import java .io .Externalizable ;
21
21
import java .io .IOException ;
22
+ import java .io .InputStream ;
22
23
import java .io .InvalidClassException ;
23
24
import java .io .ObjectInput ;
24
25
import java .io .ObjectInputStream ;
25
26
import java .io .ObjectOutput ;
26
27
import java .io .ObjectOutputStream ;
28
+ import java .io .ObjectStreamClass ;
27
29
import java .io .ObjectStreamException ;
28
30
import java .io .StreamCorruptedException ;
29
31
import java .util .Arrays ;
@@ -107,8 +109,7 @@ protected final Object readResolve() throws ObjectStreamException {
107
109
}
108
110
109
111
/* First run */
110
- try {
111
- final ObjectInputStream in = new ObjectInputStream (new ByteArrayInputStream (this .userBeanBytes ));
112
+ try (final ObjectInputStream in = new LookAheadObjectInputStream (new ByteArrayInputStream (this .userBeanBytes ))) {
112
113
this .userBean = in .readObject ();
113
114
this .unloadedProperties = (Map <String , ResultLoaderMap .LoadPair >) in .readObject ();
114
115
this .objectFactory = (ObjectFactory ) in .readObject ();
@@ -129,4 +130,30 @@ protected final Object readResolve() throws ObjectStreamException {
129
130
130
131
protected abstract Object createDeserializationProxy (Object target , Map <String , ResultLoaderMap .LoadPair > unloadedProperties , ObjectFactory objectFactory ,
131
132
List <Class <?>> constructorArgTypes , List <Object > constructorArgs );
133
+
134
+ private static class LookAheadObjectInputStream extends ObjectInputStream {
135
+ private static final List <String > blacklist = Arrays .asList (
136
+ "org.apache.commons.collections.functors.InvokerTransformer" ,
137
+ "org.apache.commons.collections.functors.InstantiateTransformer" ,
138
+ "org.apache.commons.collections4.functors.InvokerTransformer" ,
139
+ "org.apache.commons.collections4.functors.InstantiateTransformer" ,
140
+ "org.codehaus.groovy.runtime.ConvertedClosure" , "org.codehaus.groovy.runtime.MethodClosure" ,
141
+ "org.springframework.beans.factory.ObjectFactory" ,
142
+ "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" );
143
+
144
+ public LookAheadObjectInputStream (InputStream in ) throws IOException {
145
+ super (in );
146
+ }
147
+
148
+ @ Override
149
+ protected Class <?> resolveClass (ObjectStreamClass desc ) throws IOException , ClassNotFoundException {
150
+ String className = desc .getName ();
151
+ if (blacklist .contains (className )) {
152
+ throw new InvalidClassException (className , "Deserialization is not allowed for security reasons. "
153
+ + "It is strongly recommended to configure the deserialization filter provided by JDK. "
154
+ + "See http://openjdk.java.net/jeps/290 for the details." );
155
+ }
156
+ return super .resolveClass (desc );
157
+ }
158
+ }
132
159
}
0 commit comments