Xstream API を使用して Xml EXternal Entity (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 で。詳細 - https://www.owasp.org/index.php/XML_External_Entity_%28XXE%29_Prevention_Cheat_Sheet
私のコードは次のようなものです-
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;
}