Skip to content

Commit a054585

Browse files
derekstrakacowtowncoder
authored andcommitted
Fix #1737 on 2.6 (#1945)
1 parent 7da1b44 commit a054585

File tree

3 files changed

+103
-6
lines changed

3 files changed

+103
-6
lines changed

release-notes/VERSION

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Project: jackson-databind
44
=== Releases ===
55
------------------------------------------------------------------------
66

7+
2.6.7.2 (not yet released)
8+
#1737: Block more JDK types from polymorphic deserialization
9+
710
2.6.7.1 (11-Jul-2017)
811

912
#1383: Problem with `@JsonCreator` with 1-arg factory-method, implicit param names

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class BeanDeserializerFactory
4949
static {
5050
Set<String> s = new HashSet<String>();
5151
// Courtesy of [https://github.com/kantega/notsoserial]:
52-
// (and wrt [databind#1599]
52+
// (and wrt [databind#1599])
5353
s.add("org.apache.commons.collections.functors.InvokerTransformer");
5454
s.add("org.apache.commons.collections.functors.InstantiateTransformer");
5555
s.add("org.apache.commons.collections4.functors.InvokerTransformer");
@@ -58,6 +58,16 @@ public class BeanDeserializerFactory
5858
s.add("org.codehaus.groovy.runtime.MethodClosure");
5959
s.add("org.springframework.beans.factory.ObjectFactory");
6060
s.add("com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl");
61+
62+
// [databind#1737]; JDK provided
63+
s.add("java.util.logging.FileHandler");
64+
s.add("java.rmi.server.UnicastRemoteObject");
65+
// [databind#1737]; 3rd party
66+
s.add("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor");
67+
s.add("org.springframework.beans.factory.config.PropertyPathFactoryBean");
68+
s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
69+
s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
70+
6171
DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s);
6272
}
6373

src/test/java/com/fasterxml/jackson/databind/interop/IllegalTypesCheckTest.java

+89-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.databind.interop;
22

3+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
34
import com.fasterxml.jackson.databind.*;
45

56
/**
@@ -13,11 +14,28 @@ static class Bean1599 {
1314
public Object obj;
1415
}
1516

16-
public void testIssue1599() throws Exception
17+
static class PolyWrapper {
18+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,
19+
include = JsonTypeInfo.As.WRAPPER_ARRAY)
20+
public Object v;
21+
}
22+
23+
/*
24+
/**********************************************************
25+
/* Unit tests
26+
/**********************************************************
27+
*/
28+
29+
private final ObjectMapper MAPPER = objectMapper();
30+
31+
// // // Tests for [databind#1599]
32+
33+
public void testXalanTypes1599() throws Exception
1734
{
35+
final String clsName = "com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl";
1836
final String JSON = aposToQuotes(
1937
"{'id': 124,\n"
20-
+" 'obj':[ 'com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl',\n"
38+
+" 'obj':[ '"+clsName+"',\n"
2139
+" {\n"
2240
+" 'transletBytecodes' : [ 'AAIAZQ==' ],\n"
2341
+" 'transletName' : 'a.b',\n"
@@ -32,9 +50,75 @@ public void testIssue1599() throws Exception
3250
mapper.readValue(JSON, Bean1599.class);
3351
fail("Should not pass");
3452
} catch (JsonMappingException e) {
35-
verifyException(e, "Illegal type");
36-
verifyException(e, "to deserialize");
37-
verifyException(e, "prevented for security reasons");
53+
_verifySecurityException(e, clsName);
54+
}
55+
}
56+
57+
// // // Tests for [databind#1737]
58+
59+
public void testJDKTypes1737() throws Exception
60+
{
61+
_testTypes1737(java.util.logging.FileHandler.class);
62+
_testTypes1737(java.rmi.server.UnicastRemoteObject.class);
63+
}
64+
65+
// 17-Aug-2017, tatu: Ideally would test handling of 3rd party types, too,
66+
// but would require adding dependencies. This may be practical when
67+
// checking done by module, but for now let's not do that for databind.
68+
69+
/*
70+
public void testSpringTypes1737() throws Exception
71+
{
72+
_testTypes1737("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor");
73+
_testTypes1737("org.springframework.beans.factory.config.PropertyPathFactoryBean");
74+
}
75+
76+
public void testC3P0Types1737() throws Exception
77+
{
78+
_testTypes1737("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
79+
_testTypes1737("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
80+
}
81+
*/
82+
83+
private void _testTypes1737(Class<?> nasty) throws Exception {
84+
_testTypes1737(nasty.getName());
85+
}
86+
87+
private void _testTypes1737(String clsName) throws Exception
88+
{
89+
// While usually exploited via default typing let's not require
90+
// it here; mechanism still the same
91+
String json = aposToQuotes(
92+
"{'v':['"+clsName+"','/tmp/foobar.txt']}"
93+
);
94+
try {
95+
MAPPER.readValue(json, PolyWrapper.class);
96+
fail("Should not pass");
97+
} catch (JsonMappingException e) {
98+
_verifySecurityException(e, clsName);
99+
}
100+
}
101+
102+
protected void _verifySecurityException(Throwable t, String clsName) throws Exception
103+
{
104+
// 17-Aug-2017, tatu: Expected type more granular in 2.9 (over 2.8)
105+
_verifyException(t, JsonMappingException.class,
106+
"Illegal type",
107+
"to deserialize",
108+
"prevented for security reasons");
109+
verifyException(t, clsName);
110+
}
111+
112+
protected void _verifyException(Throwable t, Class<?> expExcType,
113+
String... patterns) throws Exception
114+
{
115+
Class<?> actExc = t.getClass();
116+
if (!expExcType.isAssignableFrom(actExc)) {
117+
fail("Expected Exception of type '"+expExcType.getName()+"', got '"
118+
+actExc.getName()+"', message: "+t.getMessage());
119+
}
120+
for (String pattern : patterns) {
121+
verifyException(t, pattern);
38122
}
39123
}
40124
}

0 commit comments

Comments
 (0)