Skip to content

Commit

Permalink
Fix #1599 for 2.7(.10)
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 13, 2017
1 parent 28ec8a4 commit 6ce32ff
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Project: jackson-databind

2.7.10 (not yet released)

#1599: Jackson Deserializer security vulnerability
(reported by ayound@github)
- Minor robustification of method resolution in `AnnotatedClass`

2.7.9 (04-Feb-2017)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,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 @@ -834,4 +836,25 @@ protected boolean isIgnorableType(DeserializationConfig config, BeanDescription
// We default to 'false', i.e. not ignorable
return (status == null) ? false : status.booleanValue();
}

/**
* @since 2.8.9
*/
protected 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.
Class<?> raw = type.getRawClass();
String name = raw.getSimpleName();

if ("TemplatesImpl".equals(name)) { // [databind#1599]
if (raw.getName().startsWith("com.sun.org.apache.xalan")) {
throw JsonMappingException.from(ctxt,
String.format("Illegal type (%s) to deserialize: prevented for security reasons",
name));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
}

4 comments on commit 6ce32ff

@simith003
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a null exception!
image
because you did not set _tfactory property

@cowtowncoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nike022812 I don't think that matters here as the goal is to ensure there is security exception; if not it does not matter if it fails for NPE or passes -- code should never reach that far.

@ayound
Copy link

@ayound ayound commented on 6ce32ff Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please try in jdk 1.7

@cowtowncoder
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ayound Please try what? Test passes on JDK 1.7 for me.

Please sign in to comment.