Skip to content

Commit 60d459c

Browse files
committed
Fix #1599 for 2.8.9
Merge branch '2.7' into 2.8
2 parents b64c773 + 6ce32ff commit 60d459c

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

release-notes/VERSION

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Project: jackson-databind
88
#1585: Invoke ServiceLoader.load() inside of a privileged block when loading
99
modules using `ObjectMapper.findModules()`
1010
(contributed by Ivo S)
11+
#1599: Jackson Deserializer security vulnerability
12+
(reported by ayound@github)
1113

1214
2.8.8 (05-Apr-2017)
1315

src/main/java/com/fasterxml/jackson/databind/deser/BeanDeserializerFactory.java

+49-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,36 @@ public class BeanDeserializerFactory
3838
private final static Class<?>[] INIT_CAUSE_PARAMS = new Class<?>[] { Throwable.class };
3939

4040
private final static Class<?>[] NO_VIEWS = new Class<?>[0];
41-
41+
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+
DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s);
62+
}
63+
64+
/**
65+
* Set of class names of types that are never to be deserialized.
66+
*
67+
* @since 2.8.9
68+
*/
69+
protected Set<String> _cfgIllegalClassNames = DEFAULT_NO_DESER_CLASS_NAMES;
70+
4271
/*
4372
/**********************************************************
4473
/* Life-cycle
@@ -137,6 +166,8 @@ public JsonDeserializer<Object> createBeanDeserializer(DeserializationContext ct
137166
if (!isPotentialBeanType(type.getRawClass())) {
138167
return null;
139168
}
169+
// For checks like [databind#1599]
170+
checkIllegalTypes(ctxt, type, beanDesc);
140171
// Use generic bean introspection to build deserializer
141172
return buildBeanDeserializer(ctxt, type, beanDesc);
142173
}
@@ -855,4 +886,21 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
855886
ignoredTypes.put(type, status);
856887
return status.booleanValue();
857888
}
889+
890+
/**
891+
* @since 2.8.9
892+
*/
893+
protected void checkIllegalTypes(DeserializationContext ctxt, JavaType type,
894+
BeanDescription beanDesc)
895+
throws JsonMappingException
896+
{
897+
// There are certain nasty classes that could cause problems, mostly
898+
// via default typing -- catch them here.
899+
String full = type.getRawClass().getName();
900+
901+
if (_cfgIllegalClassNames.contains(full)) {
902+
ctxt.reportBadTypeDefinition(beanDesc,
903+
"Illegal type (%s) to deserialize: prevented for security reasons", full);
904+
}
905+
}
858906
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.fasterxml.jackson.databind.interop;
2+
3+
import com.fasterxml.jackson.databind.*;
4+
5+
/**
6+
* Test case(s) to guard against handling of types that are illegal to handle
7+
* due to security constraints.
8+
*/
9+
public class IllegalTypesCheckTest extends BaseMapTest
10+
{
11+
static class Bean1599 {
12+
public int id;
13+
public Object obj;
14+
}
15+
16+
public void testIssue1599() throws Exception
17+
{
18+
final String JSON = aposToQuotes(
19+
"{'id': 124,\n"
20+
+" 'obj':[ 'com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl',\n"
21+
+" {\n"
22+
+" 'transletBytecodes' : [ 'AAIAZQ==' ],\n"
23+
+" 'transletName' : 'a.b',\n"
24+
+" 'outputProperties' : { }\n"
25+
+" }\n"
26+
+" ]\n"
27+
+"}"
28+
);
29+
ObjectMapper mapper = new ObjectMapper();
30+
mapper.enableDefaultTyping();
31+
try {
32+
mapper.readValue(JSON, Bean1599.class);
33+
fail("Should not pass");
34+
} catch (JsonMappingException e) {
35+
verifyException(e, "Illegal type");
36+
verifyException(e, "to deserialize");
37+
verifyException(e, "prevented for security reasons");
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)