@@ -38,7 +38,36 @@ public class BeanDeserializerFactory
38
38
private final static Class <?>[] INIT_CAUSE_PARAMS = new Class <?>[] { Throwable .class };
39
39
40
40
private final static Class <?>[] NO_VIEWS = new Class <?>[0 ];
41
-
41
+
42
+ /**
43
+ * Set of well-known "nasty classes", deserialization of which is considered dangerous
44
+ * and should (and is) prevented by default.
45
+ *
46
+ * @since 2.8.9
47
+ */
48
+ protected final static Set <String > DEFAULT_NO_DESER_CLASS_NAMES ;
49
+ static {
50
+ Set <String > s = new HashSet <>();
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
+ * @since 2.8.9
68
+ */
69
+ protected Set <String > _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES ;
70
+
42
71
/*
43
72
/**********************************************************
44
73
/* Life-cycle
@@ -137,6 +166,8 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
137
166
if (!isPotentialBeanType (type .getRawClass ())) {
138
167
return null ;
139
168
}
169
+ // For checks like [databind#1599]
170
+ checkIllegalTypes (ctxt , type , beanDesc );
140
171
// Use generic bean introspection to build deserializer
141
172
return buildBeanDeserializer (ctxt , type , beanDesc );
142
173
}
@@ -855,4 +886,21 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
855
886
ignoredTypes .put (type , status );
856
887
return status .booleanValue ();
857
888
}
889
+
890
+ /**
891
+ * @since 2.8.9
892
+ */
893
+ protected void checkIllegalTypes (DeserializationContext ctxt , JavaType type ,
894
+ BeanDescription beanDesc )
895
+ throws JsonMappingException
896
+ {
897
+ // There are certain nasty classes that could cause problems, mostly
898
+ // via default typing -- catch them here.
899
+ String full = type .getRawClass ().getName ();
900
+
901
+ if (_cfgIllegalClassNames .contains (full )) {
902
+ ctxt .reportBadTypeDefinition (beanDesc ,
903
+ "Illegal type (%s) to deserialize: prevented for security reasons" , full );
904
+ }
905
+ }
858
906
}
0 commit comments