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,33 @@ 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.beanutils.BeanComparator" ,
137
+ "org.apache.commons.collections.functors.InvokerTransformer" ,
138
+ "org.apache.commons.collections.functors.InstantiateTransformer" ,
139
+ "org.apache.commons.collections4.functors.InvokerTransformer" ,
140
+ "org.apache.commons.collections4.functors.InstantiateTransformer" ,
141
+ "org.codehaus.groovy.runtime.ConvertedClosure" ,
142
+ "org.codehaus.groovy.runtime.MethodClosure" ,
143
+ "org.springframework.beans.factory.ObjectFactory" ,
144
+ "org.springframework.transaction.jta.JtaTransactionManager" ,
145
+ "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" );
146
+
147
+ public LookAheadObjectInputStream (InputStream in ) throws IOException {
148
+ super (in );
149
+ }
150
+
151
+ @ Override
152
+ protected Class <?> resolveClass (ObjectStreamClass desc ) throws IOException , ClassNotFoundException {
153
+ String className = desc .getName ();
154
+ if (blacklist .contains (className )) {
155
+ throw new InvalidClassException (className , "Deserialization is not allowed for security reasons. "
156
+ + "It is strongly recommended to configure the deserialization filter provided by JDK. "
157
+ + "See http://openjdk.java.net/jeps/290 for the details." );
158
+ }
159
+ return super .resolveClass (desc );
160
+ }
161
+ }
132
162
}
0 commit comments