Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用XStream防止XXE攻击_Java_Security_Xstream_Xxe - Fatal编程技术网

Java 使用XStream防止XXE攻击

Java 使用XStream防止XXE攻击,java,security,xstream,xxe,Java,Security,Xstream,Xxe,想知道如何使用Xstream API修复Xml外部实体(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 Docu

想知道如何使用Xstream API修复Xml外部实体(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;
}
publicstaticclass[]myannotatedclass={Test1.Class,Test2.Class};
公共静态对象parseStr(字符串str)抛出XStreamException
{
XStream XStream=newxstream(new statxdriver());
processAnnotations(MyAnnotatedClass);
objectobj=xstream.fromXML(str);
返回obj;
}
根据以下内容:

StaxDriver
尝试关闭对标准StaX解析器的外部实体的支持。但是,最终使用的StAX实现是在外部定义的(参见JDK文档),应该在目标平台上进行测试,以确保解析器尊重该设置


这意味着
StaxDriver
试图告诉
StAX
实现做正确的事情,但是您正在使用的
StAX
实现可能会忽略这一点。如果它确实忽略了它,简单的答案是使用FAQ中列出的没有问题的替代驱动程序之一

有道理。将与其他驾驶员一起尝试。报告称,StaxDriver对我来说很脆弱。