Skip to content

Commit

Permalink
Backport #1599 in 2.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jul 11, 2017
1 parent 96eb83b commit fa87c1d
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -10,7 +10,7 @@

<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.8-SNAPSHOT</version>
<version>2.6.7.1-SNAPSHOT</version>
<name>jackson-databind</name>
<packaging>bundle</packaging>
<description>General data-binding functionality for Jackson: works on core streaming API</description>
Expand Down
3 changes: 2 additions & 1 deletion release-notes/VERSION
Expand Up @@ -4,9 +4,10 @@ Project: jackson-databind
=== Releases ===
------------------------------------------------------------------------

2.6.8 (if ever released)
2.6.7.1 (11-Jul-2017)

#1383: Problem with `@JsonCreator` with 1-arg factory-method, implicit param names
#1599: Backport the extra safety checks for polymorphic deserialization

2.6.7 (05-Jun-2016)

Expand Down
Expand Up @@ -40,7 +40,32 @@ 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.
*/
private 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");
DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s);
}

/**
* Set of class names of types that are never to be deserialized.
*/
private Set<String> _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES;

/*
/**********************************************************
/* Life-cycle
Expand Down Expand Up @@ -138,6 +163,8 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
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);
}
Expand Down Expand Up @@ -836,4 +863,20 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
// We default to 'false', i.e. not ignorable
return (status == null) ? false : status.booleanValue();
}

private 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)) {
String message = String.format("Illegal type (%s) to deserialize: prevented for security reasons",
full);
throw ctxt.mappingException("Invalid type definition for type %s: %s",
beanDesc, message);
}
}
}
@@ -0,0 +1,40 @@
package com.fasterxml.jackson.databind.interop;

import com.fasterxml.jackson.databind.*;

/**
* Test case(s) to guard against handling of types that are illegal to handle
* due to security constraints.
*/
public class IllegalTypesCheckTest extends BaseMapTest
{
static class Bean1599 {
public int id;
public Object obj;
}

public void testIssue1599() throws Exception
{
final String JSON = aposToQuotes(
"{'id': 124,\n"
+" 'obj':[ 'com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl',\n"
+" {\n"
+" 'transletBytecodes' : [ 'AAIAZQ==' ],\n"
+" 'transletName' : 'a.b',\n"
+" 'outputProperties' : { }\n"
+" }\n"
+" ]\n"
+"}"
);
ObjectMapper mapper = new ObjectMapper();
mapper.enableDefaultTyping();
try {
mapper.readValue(JSON, Bean1599.class);
fail("Should not pass");
} catch (JsonMappingException e) {
verifyException(e, "Illegal type");
verifyException(e, "to deserialize");
verifyException(e, "prevented for security reasons");
}
}
}

0 comments on commit fa87c1d

Please sign in to comment.