我在 veracode 报告中得到了下一个发现: XML 外部实体引用(“XXE”)的不当限制(CWE ID 611) 引用下面的下一个代码
...
DocumentBuilderFactory dbf=null;
DocumentBuilder db = null;
try {
dbf=DocumentBuilderFactory.newInstance();
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setExpandEntityReferences(false);
dbf.setXIncludeAware(false);
dbf.setValidating(false);
dbf.newDocumentBuilder();
InputStream stream = new ByteArrayInputStream(datosXml.getBytes());
Document doc = db.parse(stream, "");
...
我一直在研究,但我还没有找到这个发现的原因或让它消失的方法。 你能告诉我怎么做吗?
最佳答案
你见过the OWASP guide about XXE吗? ?
您没有禁用您应该禁用的 3 个功能。最重要的是第一个:
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
关于java - Veracode XML 外部实体引用 (XXE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61638255/