+Parsing untrusted XML files with a weakly configured XML parser may lead to an XML External Entity (XXE) attack. This type of attack +uses external entity references to access arbitrary files on a system, carry out denial of service, or server side +request forgery. Even when the result of parsing is not returned to the user, out-of-band +data retrieval techniques may allow attackers to steal sensitive data. Denial of services can also be +carried out in this situation. +
+
+There are many XML parsers for Java, and most of them are vulnerable to XXE because their default settings enable parsing of
+external entities. This query currently identifies vulnerable XML parsing from the following parsers: javax.xml.validation.Validator
,
+org.dom4j.DocumentHelper
, org.rundeck.api.parser.ParserHelper
, org.apache.commons.digester3.Digester
,
+org.apache.commons.digester.Digester
, org.apache.tomcat.util.digester.Digester
, java.beans.XMLDecoder
.
+
+The best way to prevent XXE attacks is to disable the parsing of any Document Type Declarations (DTDs) in untrusted data. +If this is not possible you should disable the parsing of external general entities and external parameter entities. +This improves security but the code will still be at risk of denial of service and server side request forgery attacks. +Protection against denial of service attacks may also be implemented by setting entity expansion limits, which is done +by default in recent JDK and JRE implementations. +
++The following bad examples parses the xml data entered by the user under an unsafe configuration, which is inherently insecure and may cause xml entity injection. +In good examples, the security configuration is carried out, for example: Disable DTD to protect the program from XXE attacks. +
+