2015-06-22 112 views
2

我已經得到了下一個發現我的Veracode的報告: XML外部實體( 'XXE')的不當限制(CWE ID 611) 指下一個代碼波紋管Veracode的XML外部實體(XXE)

...

>  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);  db = 
> dbf.newDocumentBuilder(); 
>  InputStream stream = new ByteArrayInputStream(datosXml.getBytes()); 
>  Document doc = null;   doc= db.parse(stream, ""); 

...

我一直在研究,但我還沒有發現這一發現或使之消失的一種方式的理由。 你能告訴我該怎麼做嗎?

回答

5

你見過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); 
+0

隨着新的規則,這是行不通的。 Veracode報告它 – Xelian

+0

OWASP現在增加了一個關於如何防止XXE的更廣泛的文檔:https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet 但我必須承認我不知道veracode我根本不能訪問它。所以我不能根據veracode驗證OWASP建議是否完整。但我不明白爲什麼它不再有效。也許你正在使用不同的XML解析器,需要配置有點不同? – DelGurth

+0

不,我使用以前的修復程序,Veracode停止報告它,但幾天前再次開始。我使用相同的解析器。 – Xelian