Improper Restriction of XML External Entity Reference ('XXE')
ID |
scala.xxe.scala_xxe_rule_xpathxxe |
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 unsafe3(str: String): Unit = {
val df = DocumentBuilderFactory.newInstance
val builder = df.newDocumentBuilder
val xPathFactory = XPathFactory.newInstance
val xpath = xPathFactory.newXPath
val xPathExpr = xpath.compile("/xmlhell/text()")
// VULNERABLE: Improper Restriction of XML External Entity Reference ('XXE')
xPathExpr.evaluate(new InputSource(str), null)
}
Remediation
Follow secure coding practices and review the references below for detailed remediation guidance.
References
-
OWASP Top 10 2021 - A05 : Security Misconfiguration.