Skip to content

XML External Entity (XXE) Injection

Description

XML External Entity (XXE) attacks can occur when an XML parser supports XML entities while processing XML received from an untrusted source. This can lead to unauthorized access to sensitive data, denial of service, or other malicious activities.

Examples

Insecure Code

scala
val df = DocumentBuilderFactory.newInstance
val db = df.newDocumentBuilder()
db.parse(new InputSource(new StringReader("<?xml version='1.0'?><!DOCTYPE root [<!ENTITY xxe SYSTEM 'file:///etc/passwd'>]><root>&xxe;</root>")))

Secure Code

scala
val df = DocumentBuilderFactory.newInstance
df.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
val db = df.newDocumentBuilder()
db.parse(new InputSource(new StringReader("<?xml version='1.0'?><root>data</root>")))

Remediation

To prevent XXE attacks, set the 'http://apache.org/xml/features/disallow-doctype-decl&#x27; feature to true or the 'javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING' feature to true on the DocumentBuilderFactory instance.

Rule Details

FieldValue
IDCODE-0088
CategoryInjection
SeverityMEDIUM
CWECWE-611
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
TagsXXE, XML Injection
OWASPN/A