想知道如何用Xstream修复Xstream (XXE)漏洞。
就像我们能做的那样
// This is the PRIMARY defense. If DTDs (doctypes) are disallowed, almost all XML entity attacks are prevented
// Xerces 2 only - http://xerces.apache.org/xerces2-j/features.html#disallow-doctype-decl
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
String FEATURE = null;
FEATURE = "http://apache.org/xml/features/disallow-doctype-decl";
dbf.setFeature(FEATURE, true);用DocumentBuilderFactory。更多细节- 板材
我的密码就像-
public static Class<?>[] myAnnotatedClasses = { Test1.class, Test2.class };
public static Object parseStr(String str) throws XStreamException
{
XStream xstream = new XStream(new StaxDriver());
xstream.processAnnotations(myAnnotatedClasses);
Object obj =xstream.fromXML(str);
return obj;
}发布于 2016-10-12 15:01:15
根据XStream常见问题
StaxDriver试图关闭对标准StaX解析器的外部实体的支持。但是,最后使用的StAX实现是外部定义的(参见JDK文档),应该在目标平台上进行测试,以确保解析器尊重设置。
这意味着StaxDriver试图告诉StAX实现做正确的事情,但是您使用的StAX实现可能忽略这一点。如果它确实忽略了它,简单的答案是使用FAQ中列出的一个没有问题的替代驱动程序。
https://stackoverflow.com/questions/40000957
复制相似问题