Skip to content

Commit 80566a0

Browse files
cowtowncodertolbertam
authored andcommitted
1 parent e8f043d commit 80566a0

File tree

3 files changed

+100
-6
lines changed

3 files changed

+100
-6
lines changed

release-notes/VERSION

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Project: jackson-databind
1111
#1628: Don't print to error stream about failure to load JDK 7 types
1212
(reported by Villane@github)
1313
#1680: Blacklist couple more types for deserialization
14+
#1737: Block more JDK types from polymorphic deserialization
1415

1516
2.7.9.1 (18-Apr-2017)
1617

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class BeanDeserializerFactory
4848
static {
4949
Set<String> s = new HashSet<String>();
5050
// Courtesy of [https://github.com/kantega/notsoserial]:
51-
// (and wrt [databind#1599]
51+
// (and wrt [databind#1599])
5252
s.add("org.apache.commons.collections.functors.InvokerTransformer");
5353
s.add("org.apache.commons.collections.functors.InstantiateTransformer");
5454
s.add("org.apache.commons.collections4.functors.InvokerTransformer");
@@ -60,6 +60,15 @@ public class BeanDeserializerFactory
6060
s.add("org.apache.xalan.xsltc.trax.TemplatesImpl");
6161
// [databind#1680]: may or may not be problem, take no chance
6262
s.add("com.sun.rowset.JdbcRowSetImpl");
63+
// [databind#1737]; JDK provided
64+
s.add("java.util.logging.FileHandler");
65+
s.add("java.rmi.server.UnicastRemoteObject");
66+
// [databind#1737]; 3rd party
67+
s.add("org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor");
68+
s.add("org.springframework.beans.factory.config.PropertyPathFactoryBean");
69+
s.add("com.mchange.v2.c3p0.JndiRefForwardingDataSource");
70+
s.add("com.mchange.v2.c3p0.WrapperConnectionPoolDataSource");
71+
6372
DEFAULT_NO_DESER_CLASS_NAMES = Collections.unmodifiableSet(s);
6473
}
6574

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
/**
@@ -12,12 +13,29 @@ static class Bean1599 {
1213
public int id;
1314
public Object obj;
1415
}
16+
17+
static class PolyWrapper {
18+
@JsonTypeInfo(use = JsonTypeInfo.Id.CLASS,
19+
include = JsonTypeInfo.As.WRAPPER_ARRAY)
20+
public Object v;
21+
}
1522

16-
public void testIssue1599() throws Exception
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)