Xalan Transformer 功能

Xalan Transformer features

我运行 一次 Fortify 扫描以排除安全漏洞。它建议我将以下功能设置为我的 XML Document to XML String t运行sformer.

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

这会导致异常,因为这些字符串不存在。 XMLConstants.FEATURE_SECURE_PROCESSING 有一个选项,但我不清楚是否阻止使用外部实体。 JavaDoc 指出:"true instructs the implementation to process XML securely. This may set limits on XML constructs to avoid conditions such as denial of service attacks."

tf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

如上面评论所述,这些功能需要在 XML 解析器中设置,而不是 XSLT 转换器。