提交 d030fbba 编写于 作者: J Jesse Glick

[FIXED SECURITY-105] Disabling DynamicProxyConverter.

上级 7541e83c
......@@ -29,6 +29,7 @@ import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.mapper.AnnotationMapper;
import com.thoughtworks.xstream.mapper.Mapper;
import com.thoughtworks.xstream.mapper.MapperWrapper;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.ConverterMatcher;
import com.thoughtworks.xstream.converters.DataHolder;
......@@ -36,6 +37,7 @@ import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.SingleValueConverter;
import com.thoughtworks.xstream.converters.SingleValueConverterWrapper;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.converters.extended.DynamicProxyConverter;
import com.thoughtworks.xstream.core.JVM;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
......@@ -155,6 +157,15 @@ public class XStream2 extends XStream {
// this should come after all the XStream's default simpler converters,
// but before reflection-based one kicks in.
registerConverter(new AssociatedConverterImpl(this), -10);
registerConverter(new DynamicProxyConverter(getMapper()) { // SECURITY-105 defense
@Override public boolean canConvert(Class type) {
return /* this precedes NullConverter */ type != null && super.canConvert(type);
}
@Override public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
throw new ConversionException("<dynamic-proxy> not supported");
}
}, PRIORITY_VERY_HIGH);
}
@Override
......
......@@ -25,6 +25,7 @@ package hudson.util;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.thoughtworks.xstream.XStreamException;
import hudson.XmlFile;
import hudson.matrix.MatrixRun;
import hudson.model.Result;
......@@ -312,6 +313,21 @@ public class XStream2Test extends TestCase {
assertEquals("def",map.m.get("abc"));
}
public void testDynamicProxyBlocked() throws Exception { // SECURITY-105
try {
((Runnable) new XStream2().fromXML("<dynamic-proxy><interface>java.lang.Runnable</interface><handler class='java.beans.EventHandler'><target class='" + Hacked.class.getName() + "'/><action>oops</action></handler></dynamic-proxy>")).run();
} catch (XStreamException x) {
// good
}
assertFalse("should never have run that", Hacked.tripped);
}
public static final class Hacked {
static boolean tripped;
public void oops() {
tripped = true;
}
}
public void testTrimVersion() throws Exception {
assertEquals("3.2", XStream2.trimVersion("3.2"));
assertEquals("3.2.1", XStream2.trimVersion("3.2.1"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册