Skip to content

Missing secure configuration in DocumentBuilderFactory

Description

DocumentBuilderFactory is used without disabling DOCTYPE declarations or external entity features, which can expose the application to XML External Entity (XXE) attacks, leading to reading internal server files, Denial of Service, or Server-Side Request Forgery (SSRF).

Examples

Insecure Code

java
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

Secure Code

java
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// OR
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);

Remediation

Set one of the following combinations: disallow-doctype-decl = true OR external-general-entities = false AND external-parameter-entities = false

Rule Details

FieldValue
IDCODE-0002
CategoryInjection
SeverityMEDIUM
CWECWE-611
ConfidenceHIGH
ImpactHIGH
LikelihoodMEDIUM
ExploitabilityEASY
TagsXXE, XML External Entity
OWASPA05:2021-Security Misconfiguration