Skip to content

Improper Restriction of XML External Entity Reference ('XXE')

Description

The XMLReaderFactory is used without proper restriction of XML external entity references, allowing potential XXE attacks. This can lead to file reading, external host communication, data exfiltration, or Denial of Service (DoS).

Examples

Insecure Code

java
$R = XMLReaderFactory.createXMLReader();
$R.parse(...);

Secure Code

java
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
SAXParser parser = saxParserFactory.newSAXParser();
parser.parse(new FileInputStream(new File("bad.xml")), new DefaultHandler());

Remediation

Use SAXParserFactory instead of XMLReaderFactory and configure it to disallow doctypes by setting the feature 'http://apache.org/xml/features/disallow-doctype-decl' to true.

Rule Details

FieldValue
IDCODE-0735
CategoryInjection
SeverityMEDIUM
CWECWE-611
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
TagsXXE, XML External Entity
OWASPA1:2017-Injection, A03:2021-Injection