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

ID

scala.xxe.scala_xxe_rule_xmlstreamrdr

Severity

high

Resource

Xxe

Language

Scala

Description

XML External Entity (XXE) attacks can occur when an XML parser supports XML entities while processing XML received from an untrusted source.

Rationale

XML External Entity (XXE) attacks can occur when an XML parser supports XML entities while processing XML received from an untrusted source.

The following code illustrates a vulnerable pattern detected by this rule:

def parseXMLUnsafe(input: InputStream): Unit = {
  val factory = XMLInputFactory.newFactory
  factory.setProperty(XMLInputFactory.SUPPORT_DTD, true)
  // VULNERABLE: Improper Restriction of XML External Entity Reference ('XXE')
  val reader = factory.createXMLStreamReader(input)
  while ( {
    reader.hasNext
  }) reader.next
}

Remediation

Follow secure coding practices and review the references below for detailed remediation guidance.

Configuration

This detector does not need any configuration.

References