diff --git a/ant/build-test.xml b/ant/build-test.xml index 787369224..79af390b3 100644 --- a/ant/build-test.xml +++ b/ant/build-test.xml @@ -100,7 +100,9 @@ test.run.interop, test.run.jaxrs, test.run.failing, test.run.versions" /> - + + @@ -129,7 +131,9 @@ test.run.interop, test.run.jaxrs, test.run.failing, test.run.versions" - + + @@ -154,7 +158,9 @@ test.run.interop, test.run.jaxrs, test.run.failing, test.run.versions" - + + diff --git a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializerFactory.java b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializerFactory.java index 620c9dce4..f0fff683d 100644 --- a/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializerFactory.java +++ b/src/mapper/java/org/codehaus/jackson/map/deser/BeanDeserializerFactory.java @@ -31,6 +31,18 @@ public class BeanDeserializerFactory */ private final static Class[] INIT_CAUSE_PARAMS = new Class[] { Throwable.class }; + + protected final static Set ALLOW_DESER_PACKAGES; + + static { + String strlist = System.getProperty("jackson.deserialization.whitelist.packages"); + Set s = new HashSet(); + if(strlist != null) + s = new HashSet(Arrays.asList(strlist.split(","))); + ALLOW_DESER_PACKAGES = Collections.unmodifiableSet(s); + } + + /* /********************************************************** /* Config class implementation @@ -632,10 +644,32 @@ public JsonDeserializer createBeanDeserializer(DeserializationConfig con if (!isPotentialBeanType(type.getRawClass())) { return null; } + + //Don't allow dangerous deserialization without a whitelist + //https://github.com/mbechler/marshalsec/blob/master/marshalsec.pdf + checkLegalTypes(type); + // Use generic bean introspection to build deserializer return buildBeanDeserializer(config, type, beanDesc, property); } + protected void checkLegalTypes(JavaType type) throws JsonMappingException { + String full = type.getRawClass().getName(); + Iterator iter = ALLOW_DESER_PACKAGES.iterator(); + + boolean pass = false; + while(iter.hasNext()){ + if(full.startsWith(iter.next())){ + pass = true; + break; + } + } + if(!pass) + throw new JsonMappingException( + String.format("Illegal type (%s) to deserialize: prevented for security reasons", full)); + + } + /** * Method that will find abstract type mapping for specified type, doing a single * lookup through registered abstract type resolvers; will not do recursive lookups.