diff --git a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java index a10cc45..c040fb9 100644 --- a/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java +++ b/src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java @@ -44,7 +44,33 @@ public class BeanDeserializerFactory private final static Class<?>[] INIT_CAUSE_PARAMS = new Class<?>[] { Throwable.class }; private final static Class<?>[] NO_VIEWS = new Class<?>[0]; - + + /** + * Set of well-known "nasty classes", deserialization of which is considered dangerous + * and should (and is) prevented by default. + */ + protected final static Set<String> DEFAULT_NO_DESER_CLASS_NAMES; + static { + Set<String> s = new HashSet<String>(); + // Courtesy of [https://github.com/kantega/notsoserial]: + // (and wrt [databind#1599] + s.add("org.apache.commons.collections.functors.InvokerTransformer"); + s.add("org.apache.commons.collections.functors.InstantiateTransformer"); + s.add("org.apache.commons.collections4.functors.InvokerTransformer"); + s.add("org.apache.commons.collections4.functors.InstantiateTransformer"); + s.add("org.codehaus.groovy.runtime.ConvertedClosure"); + s.add("org.codehaus.groovy.runtime.MethodClosure"); + s.add("org.springframework.beans.factory.ObjectFactory"); + s.add("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl"); + s.add("org.apache.xalan.xsltc.trax.TemplatesImpl"); + DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s); + } + + /** + * Set of class names of types that are never to be deserialized. + */ + protected Set<String> _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES; + /* /********************************************************** /* Life-cycle @@ -164,6 +190,10 @@ public class BeanDeserializerFactory if (!isPotentialBeanType(type.getRawClass())) { return null; } + + // For checks like [databind#1599] + checkIllegalTypes(ctxt, type, beanDesc); + // Use generic bean introspection to build deserializer return buildBeanDeserializer(ctxt, type, beanDesc); } @@ -875,4 +905,18 @@ public class BeanDeserializerFactory } return status; } + + protected void checkIllegalTypes(DeserializationContext ctxt, JavaType type, + BeanDescription beanDesc) + throws JsonMappingException + { + // There are certain nasty classes that could cause problems, mostly + // via default typing -- catch them here. + String full = type.getRawClass().getName(); + + if (_cfgIllegalClassNames.contains(full)) { + throw JsonMappingException.from(ctxt.getParser(), + String.format("Illegal type (%s) to deserialize: prevented for security reasons", full)); + } + } }