|
12 | 12 | import com.fasterxml.jackson.databind.deser.std.ThrowableDeserializer;
|
13 | 13 | import com.fasterxml.jackson.databind.introspect.*;
|
14 | 14 | import com.fasterxml.jackson.databind.jsontype.TypeDeserializer;
|
| 15 | +import com.fasterxml.jackson.databind.jsontype.impl.SubTypeValidator; |
| 16 | +import com.fasterxml.jackson.databind.util.ArrayBuilders; |
15 | 17 | import com.fasterxml.jackson.databind.util.ClassUtil;
|
16 | 18 | import com.fasterxml.jackson.databind.util.SimpleBeanPropertyDefinition;
|
17 | 19 |
|
@@ -39,50 +41,6 @@ public class BeanDeserializerFactory
|
39 | 41 |
|
40 | 42 | private final static Class<?>[] NO_VIEWS = new Class<?>[0];
|
41 | 43 |
|
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 |
| - s.add("org.apache.xalan.xsltc.trax.TemplatesImpl"); |
62 |
| - // [databind#1680]: may or may not be problem, take no chance |
63 |
| - s.add("com.sun.rowset.JdbcRowSetImpl"); |
64 |
| - // [databind#1737]; JDK provided |
65 |
| - s.add("java.util.logging.FileHandler"); |
66 |
| - s.add("java.rmi.server.UnicastRemoteObject"); |
67 |
| - // [databind#1737]; 3rd party |
68 |
| - s.add("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor"); |
69 |
| - s.add("org.springframework.beans.factory.config.PropertyPathFactoryBean"); |
70 |
| - s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource"); |
71 |
| - s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource"); |
72 |
| - |
73 |
| - // [databind#1855]: more 3rd party |
74 |
| - s.add("org.apache.tomcat.dbcp.dbcp2.BasicDataSource"); |
75 |
| - s.add("com.sun.org.apache.bcel.internal.util.ClassLoader"); |
76 |
| - DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s); |
77 |
| - } |
78 |
| - |
79 |
| - /** |
80 |
| - * Set of class names of types that are never to be deserialized. |
81 |
| - * |
82 |
| - * @since 2.8.9 |
83 |
| - */ |
84 |
| - protected Set<String> _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES; |
85 |
| - |
86 | 44 | /*
|
87 | 45 | /**********************************************************
|
88 | 46 | /* Life-cycle
|
@@ -182,7 +140,7 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
|
182 | 140 | return null;
|
183 | 141 | }
|
184 | 142 | // For checks like [databind#1599]
|
185 |
| - checkIllegalTypes(ctxt, type, beanDesc); |
| 143 | + _validateSubType(ctxt, type, beanDesc); |
186 | 144 | // Use generic bean introspection to build deserializer
|
187 | 145 | return buildBeanDeserializer(ctxt, type, beanDesc);
|
188 | 146 | }
|
@@ -900,19 +858,12 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
|
900 | 858 | }
|
901 | 859 |
|
902 | 860 | /**
|
903 |
| - * @since 2.8.9 |
| 861 | + * @since 2.8.11 |
904 | 862 | */
|
905 |
| - protected void checkIllegalTypes(DeserializationContext ctxt, JavaType type, |
| 863 | + protected void _validateSubType(DeserializationContext ctxt, JavaType type, |
906 | 864 | BeanDescription beanDesc)
|
907 | 865 | throws JsonMappingException
|
908 | 866 | {
|
909 |
| - // There are certain nasty classes that could cause problems, mostly |
910 |
| - // via default typing -- catch them here. |
911 |
| - String full = type.getRawClass().getName(); |
912 |
| - |
913 |
| - if (_cfgIllegalClassNames.contains(full)) { |
914 |
| - ctxt.reportBadTypeDefinition(beanDesc, |
915 |
| - "Illegal type (%s) to deserialize: prevented for security reasons", full); |
916 |
| - } |
| 867 | + SubTypeValidator.instance().validateSubType(ctxt, type); |
917 | 868 | }
|
918 | 869 | }
|
0 commit comments