【问题标题】:XML parser configured here does not prevent nor limit external entities resolution此处配置的 XML 解析器不会阻止也不会限制外部实体解析
【发布时间】:2015-11-27 06:19:00
【问题描述】:

当我在这个程序上运行 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 外部实体攻击。

根据这个blog,应该设置以下功能。

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

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

【问题讨论】:

    标签: java fortify


    【解决方案1】:

    您必须找到一种不同的方法来防止您的转换器扩展您不需要的任何外部实体。 这可能需要破解您的转换器,重写它,甚至预处理您的 XML 以检测实体并引发异常。

    【讨论】:

      猜你喜欢
      • 2017-09-09
      • 2017-04-04
      • 1970-01-01
      • 2015-11-19
      • 2010-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-11
      相关资源
      最近更新 更多