Summary
AssertJ's XML formatting and comparison utilities process XML with default DocumentBuilderFactory settings, leaving XML external entities and DTDs enabled.
When applications pass untrusted XML into isXmlEqualTo(CharSequence) or xmlPrettyFormat(String), attackers may read local files, trigger SSRF, or cause denial-of-service via entity expansion.
Affected context
This vulnerability manifests in Java applications and test suites that:
- Use AssertJ versions from 1.4.0 up to (but excluding) 3.27.7
- Call
isXmlEqualTo(CharSequence)fromorg.assertj.core.api.AbstractCharSequenceAssert
and/or xmlPrettyFormat(String) from org.assertj.core.util.xml.XmlStringPrettyFormatter
- Pass XML content that can be influenced, controlled, or injected by an attacker
It is particularly relevant where test helpers or diagnostics inadvertently execute against untrusted XML (for example, parsing responses from external services or inputs stored in test fixtures that derive from user data).
Exploit preconditions
- Attack surface: Java/JVM code paths that invoke:
AbstractCharSequenceAssert.isXmlEqualTo(CharSequence)XmlStringPrettyFormatter.xmlPrettyFormat(String)- Required access: Ability to supply or modify XML content passed into these APIs (e.g., via user-submitted data, test harness input, logs, or external service responses).
- Trigger point: The vulnerable methods internally call
toXmlDocument(String), which creates aDocumentBuilderFactorywith default, insecure settings, allowing DTDs and external entities. - Why exploitation is possible: Because XXE-related features are not disabled, the XML parser resolves external entities. Crafted XML can reference local files (
file://), internal network endpoints (http://,https://), or use recursive entities (Billion Laughs) that the parser will attempt to process.
Why this happens
The root cause is the use of DocumentBuilderFactory with default configuration in org.assertj.core.util.xml.XmlStringPrettyFormatter.toXmlDocument(String), without explicitly disabling DTDs and external entities or enabling secure processing features.
This aligns with CWE-611: Improper Restriction of XML External Entity Reference, where XML parsers process external entities from untrusted input, enabling attackers to reach resources beyond the intended trust boundary. In this case, AssertJ's XML utilities, originally meant as testing helpers, behave as generic XML parsers but do not enforce secure parsing options, exposing XXE when given untrusted XML data.
Potential impact
- Read arbitrary local files accessible to the AssertJ process via
file://URIs (e.g.,/etc/passwd, application configuration files, private keys). - Perform Server-Side Request Forgery (SSRF) by making the application initiate HTTP/HTTPS requests to internal or external endpoints.
- Exfiltrate data from internal network services by encoding responses in XML entity expansions.
- Cause Denial of Service via entity expansion attacks such as the "Billion Laughs" pattern, consuming CPU and memory.
- Assist in reconnaissance of the host and internal network environment, potentially supporting further compromise.
General mitigation guidance
Effective mitigation focuses on treating all XML input as untrusted by default and enforcing secure parsing patterns:
- Prefer alternative assertion libraries specifically designed for XML comparison (e.g., XMLUnit) that default to secure XML parsing and provide documented XXE hardening options.
- Configure XML parsers with secure processing features when custom XML handling is required:
- Disable DTDs and external entity resolution.
- Enable secure processing limits (entity expansion, depth, and size limits).
- Avoid using test utilities or assertion helpers that perform XML parsing on untrusted or user-controlled XML. Restrict such usage to controlled, static test data.
- Isolate XML parsing logic into well-reviewed, shared utility components that enforce safe defaults, rather than ad hoc creation of
DocumentBuilderFactoryin multiple locations. - Apply least privilege to the runtime environment: restrict file system access where feasible and limit outbound network access from testing or application processes to reduce the blast radius of any XXE that occurs.
How teams detect issues like this
Detection generally relies on combining code-level analysis, configuration review, and targeted testing:
- Static analysis and code search:
- Search for uses of
DocumentBuilderFactory.newInstance()and check whether secure features are explicitly set: - Disabling DTDs and external entities
- Enabling secure processing
- Flag direct uses of
isXmlEqualTo(CharSequence)andXmlStringPrettyFormatter.xmlPrettyFormat(String)in codebases that may handle external or user-derived XML. - Code review practices:
- Treat any XML parsing in assertions, tests, or debug utilities as security-relevant, especially in integration or end-to-end tests that may touch real services or external inputs.
- Verify that XML handling utilities are centralized and hardened rather than duplicated.
- Dynamic testing:
- Introduce XXE proof-of-concept payloads into test XML inputs to observe whether outbound requests, file reads, or DoS symptoms occur.
- Automated tooling:
- Configure SAST tools with rules for CWE-611 to flag insecure XML parser configurations.
- Use dependency scanning tools and SBOM-based policies to highlight vulnerable AssertJ versions and encourage secure upgrades.

