1
分辨率當我對這個方案運行HP Fortify的:XML解析器此處配置不阻止也不限制外部實體
DOMSource domSource = new DOMSource(document);
ByteArrayOutputStream bos=new ByteArrayOutputStream();
StreamResult result = new StreamResult(bos);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer;
try {
transformer = tf.newTransformer();
transformer.transform(domSource, result);
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我得到這個錯誤:
XML parser configured in ItemServlet.java:92 does not prevent nor limit external entities resolution. This can expose the parser to an XML External Entities attack.
根據這一blog,以下功能應該設置。
tf.setFeature("http://xml.org/sax/features/external-general-entities", false);
tf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
但問題是,我的TransformerFactory
實例不支持此方法。