@@ -39,7 +39,32 @@ public class BeanDeserializerFactory
39
39
private final static Class <?>[] INIT_CAUSE_PARAMS = new Class <?>[] { Throwable .class };
40
40
41
41
private final static Class <?>[] NO_VIEWS = new Class <?>[0 ];
42
-
42
+
43
+ /**
44
+ * Set of well-known "nasty classes", deserialization of which is considered dangerous
45
+ * and should (and is) prevented by default.
46
+ */
47
+ protected final static Set <String > DEFAULT_NO_DESER_CLASS_NAMES ;
48
+ static {
49
+ Set <String > s = new HashSet <String >();
50
+ // Courtesy of [https://github.com/kantega/notsoserial]:
51
+ // (and wrt [databind#1599]
52
+ s .add ("org.apache.commons.collections.functors.InvokerTransformer" );
53
+ s .add ("org.apache.commons.collections.functors.InstantiateTransformer" );
54
+ s .add ("org.apache.commons.collections4.functors.InvokerTransformer" );
55
+ s .add ("org.apache.commons.collections4.functors.InstantiateTransformer" );
56
+ s .add ("org.codehaus.groovy.runtime.ConvertedClosure" );
57
+ s .add ("org.codehaus.groovy.runtime.MethodClosure" );
58
+ s .add ("org.springframework.beans.factory.ObjectFactory" );
59
+ s .add ("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl" );
60
+ DEFAULT_NO_DESER_CLASS_NAMES = Collections .unmodifiableSet (s );
61
+ }
62
+
63
+ /**
64
+ * Set of class names of types that are never to be deserialized.
65
+ */
66
+ protected Set <String > _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES ;
67
+
43
68
/*
44
69
/**********************************************************
45
70
/* Life-cycle
@@ -846,15 +871,11 @@ protected void checkIllegalTypes(DeserializationContext ctxt, JavaType type,
846
871
{
847
872
// There are certain nasty classes that could cause problems, mostly
848
873
// via default typing -- catch them here.
849
- Class <?> raw = type .getRawClass ();
850
- String name = raw .getSimpleName ();
851
-
852
- if ("TemplatesImpl" .equals (name )) { // [databind#1599]
853
- if (raw .getName ().startsWith ("com.sun.org.apache.xalan" )) {
854
- throw JsonMappingException .from (ctxt ,
855
- String .format ("Illegal type (%s) to deserialize: prevented for security reasons" ,
856
- name ));
857
- }
874
+ String full = type .getRawClass ().getName ();
875
+
876
+ if (_cfgIllegalClassNames .contains (full )) {
877
+ throw JsonMappingException .from (ctxt ,
878
+ String .format ("Illegal type (%s) to deserialize: prevented for security reasons" , full ));
858
879
}
859
880
}
860
881
}
0 commit comments