Java 此处配置的XML解析器不会阻止或限制外部实体解析

Java 此处配置的XML解析器不会阻止或限制外部实体解析,java,fortify,Java,Fortify,当我在此程序上运行HP Fortify时: DOMSource domSource = new DOMSource(document); ByteArrayOutputStream bos=new ByteArrayOutputStream(); StreamResult result = new StreamResult(bos); TransformerFactory tf = TransformerFactory.newInstance(); Tr

当我在此程序上运行HP Fortify时:

    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();
    }
我得到这个错误:

在ItemServlet.java:92中配置的XML解析器不会阻止或限制外部实体解析。这会使解析器受到XML外部实体攻击

据此,应设置以下功能

tf.setFeature("http://xml.org/sax/features/external-general-entities", false);
tf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);

但问题是我的
TransformerFactory
实例不支持此方法。

您必须找到不同的方法来防止您的转换器扩展任何不需要的外部实体。
这可能需要对转换器进行黑客攻击、重写,甚至对XML进行预处理,以检测实体并引发异常。

您必须找到另一种方法来防止转换器扩展任何不需要的外部实体。 这可能需要对转换器进行黑客攻击、重写,甚至对XML进行预处理,以检测实体并引发异常