Skip to content

XML External Entity (XXE) Vulnerability

Description

XML External Entity (XXE) attacks can occur when an XML parser supports XML entities while processing XML received from an untrusted source. This rule detects the creation of an XMLStreamReader without properly restricting XML external entity references.

Examples

Insecure Code

scala
val factory = XMLInputFactory.newFactory
val reader = factory.createXMLStreamReader(new StringReader(xml))

Secure Code

scala
val factory = XMLInputFactory.newFactory
factory.setProperty(XMLInputFactory.SUPPORT_DTD, false)
factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false)
val reader = factory.createXMLStreamReader(new StringReader(xml))

Remediation

Set the SUPPORT_DTD property to false and the IS_SUPPORTING_EXTERNAL_ENTITIES property to false on the XMLInputFactory instance before creating an XMLStreamReader.

Rule Details

FieldValue
IDCODE-0092
CategoryInjection
SeverityMEDIUM
CWECWE-611
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityMODERATE
TagsXXE, XML External Entity
OWASPN/A