@@ -38,7 +38,36 @@ public class BeanDeserializerFactory
3838 private final static Class <?>[] INIT_CAUSE_PARAMS = new Class <?>[] { Throwable .class };
3939
4040 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+
4271 /*
4372 /**********************************************************
4473 /* Life-cycle
@@ -137,6 +166,8 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
137166 if (!isPotentialBeanType (type .getRawClass ())) {
138167 return null ;
139168 }
169+ // For checks like [databind#1599]
170+ checkIllegalTypes (ctxt , type , beanDesc );
140171 // Use generic bean introspection to build deserializer
141172 return buildBeanDeserializer (ctxt , type , beanDesc );
142173 }
@@ -855,4 +886,21 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
855886 ignoredTypes .put (type , status );
856887 return status .booleanValue ();
857888 }
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+ }
858906}
0 commit comments