@@ -40,7 +40,32 @@ public class BeanDeserializerFactory
40
40
private final static Class <?>[] INIT_CAUSE_PARAMS = new Class <?>[] { Throwable .class };
41
41
42
42
private final static Class <?>[] NO_VIEWS = new Class <?>[0 ];
43
-
43
+
44
+ /**
45
+ * Set of well-known "nasty classes", deserialization of which is considered dangerous
46
+ * and should (and is) prevented by default.
47
+ */
48
+ private final static Set <String > DEFAULT_NO_DESER_CLASS_NAMES ;
49
+ static {
50
+ Set <String > s = new HashSet <String >();
51
+ // Courtesy of [https://github.com/kantega/notsoserial]:
52
+ // (and wrt [databind#1599]
53
+ s .add ("org.apache.commons.collections.functors.InvokerTransformer" );
54
+ s .add ("org.apache.commons.collections.functors.InstantiateTransformer" );
55
+ s .add ("org.apache.commons.collections4.functors.InvokerTransformer" );
56
+ s .add ("org.apache.commons.collections4.functors.InstantiateTransformer" );
57
+ s .add ("org.codehaus.groovy.runtime.ConvertedClosure" );
58
+ s .add ("org.codehaus.groovy.runtime.MethodClosure" );
59
+ s .add ("org.springframework.beans.factory.ObjectFactory" );
60
+ s .add ("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" );
61
+ DEFAULT_NO_DESER_CLASS_NAMES = Collections .unmodifiableSet (s );
62
+ }
63
+
64
+ /**
65
+ * Set of class names of types that are never to be deserialized.
66
+ */
67
+ private Set <String > _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES ;
68
+
44
69
/*
45
70
/**********************************************************
46
71
/* Life-cycle
@@ -138,6 +163,8 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
138
163
if (!isPotentialBeanType (type .getRawClass ())) {
139
164
return null ;
140
165
}
166
+ // For checks like [databind#1599]
167
+ checkIllegalTypes (ctxt , type , beanDesc );
141
168
// Use generic bean introspection to build deserializer
142
169
return buildBeanDeserializer (ctxt , type , beanDesc );
143
170
}
@@ -836,4 +863,20 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
836
863
// We default to 'false', i.e. not ignorable
837
864
return (status == null ) ? false : status .booleanValue ();
838
865
}
866
+
867
+ private void checkIllegalTypes (DeserializationContext ctxt , JavaType type ,
868
+ BeanDescription beanDesc )
869
+ throws JsonMappingException
870
+ {
871
+ // There are certain nasty classes that could cause problems, mostly
872
+ // via default typing -- catch them here.
873
+ String full = type .getRawClass ().getName ();
874
+
875
+ if (_cfgIllegalClassNames .contains (full )) {
876
+ String message = String .format ("Illegal type (%s) to deserialize: prevented for security reasons" ,
877
+ full );
878
+ throw ctxt .mappingException ("Invalid type definition for type %s: %s" ,
879
+ beanDesc , message );
880
+ }
881
+ }
839
882
}
0 commit comments