Skip to content
Back to Blog
·9 min read·technology

XXE Injection: XML External Entity Attacks for Indian Developers

XXE injection exploits XML parsers to read server files and trigger SSRF. Learn to detect and fix XML External Entity attacks in Java and Python applications.

BR

Bachao.AI Research Team

Cybersecurity Research

Scan Your Attack Surface

Security exposure this creates

Unpatched vulnerabilities in your tech stack are the #1 entry point for breaches targeting Indian businesses. Here's what to watch.

XML External Entity (XXE) injection is a server-side vulnerability that lets an attacker hijack an application's XML parser to read arbitrary local files, trigger server-side request forgery (SSRF), exfiltrate data through blind out-of-band channels, or crash the server entirely. The attack works by embedding a malicious Document Type Definition (DTD) inside XML input — the parser dutifully fetches whatever the attacker points it at, including /etc/passwd, AWS instance metadata endpoints, or remote attacker-controlled servers. Any application that accepts XML — SOAP APIs, SAML logins, file uploads including DOCX, XLSX, and SVG — is potentially exposed. XXE requires no authentication and no memory corruption. A single misconfigured parser flag is enough.

XXE ranked #4 in the OWASP Top 10 (2017) before being absorbed into Security Misconfiguration (A05) in the 2021 edition — a recognition that the root cause is almost always a parser left in its unsafe default state. For Indian enterprises running Java-heavy middleware, SOAP-based fintech integrations, or SAML-authenticated portals, XXE remains one of the most underestimated attack surfaces in production today.

How an XXE Attack Works

An XML parser is designed to resolve entities declared in the DTD automatically. Most parsers honour external entities by default — meaning they will fetch a URL or read a file path embedded inside the XML they receive. Attackers exploit this by crafting XML that defines a custom entity pointing to a sensitive resource:

xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<userProfile>
  <username>&xxe;</username>
</userProfile>

When the server parses this, it replaces &xxe; with the contents of /etc/passwd and potentially returns it inline — inside a response body, an error message, or even a log file that reaches the attacker later.

The Full Attack Chain

graph TD A[Attacker crafts malicious XML
with external entity in DTD] --> B[XML submitted to server
SOAP - SAML - file upload - REST] B --> C{Parser resolves
external entities?} C -->|Yes — default config| D[External entity loaded
by XML parser] C -->|No — hardened config| Z[Request blocked — safe] D --> E[Local file read
passwd - env - SSH keys] D --> F[SSRF to internal network
or cloud metadata service] D --> G[Blind XXE via OOB
DNS or HTTP callback] D --> H[Billion Laughs expansion
causes server DoS] E --> I[Attacker receives
sensitive data] F --> I G --> I style A fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style B fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style C fill:#1e3a5f,stroke:#3B82F6,color:#e2e8f0 style D fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style E fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style F fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style G fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style H fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style I fill:#5f1e1e,stroke:#EF4444,color:#e2e8f0 style Z fill:#1e3d2f,stroke:#10B981,color:#e2e8f0

The Four XXE Attack Variants

1. Classic XXE — File Read

The most straightforward form. The server returns the entity value in the HTTP response. High-value targets include /etc/passwd, /etc/shadow, application configuration files, .env files containing database credentials, SSH private keys, and ~/.aws/credentials. For a cloud-hosted application, reading that last file hands the attacker IAM credentials without any authentication.

2. SSRF via XXE

By pointing the entity to an HTTP URL instead of a file path, the attacker makes the server issue internal HTTP requests on their behalf. The most damaging target in AWS environments is:

http://169.254.169.254/latest/meta-data/iam/security-credentials/

This endpoint returns temporary IAM role credentials — no VPN, no account, no prior access required. The same technique targets GCP's metadata service (http://metadata.google.internal/) and Azure's IMDS endpoint. For Indian startups running on AWS or GCP, XXE-based SSRF is a direct path to full cloud account compromise.

3. Blind XXE with Out-of-Band Exfiltration

When the server does not return the entity value in its HTTP response, the attacker shifts to an out-of-band (OOB) technique. The malicious entity triggers a DNS lookup or HTTP callback to an attacker-controlled server, confirming exploitability and carrying data encoded in the subdomain or query string. Tools like Burp Collaborator or the open-source interactsh platform are used to catch these callbacks.

Blind XXE is common in Java enterprise applications where XML parsing errors are silently caught and discarded — the parse succeeds and triggers the external request, but nothing appears in the response. It is harder to detect during manual code review and requires active testing to surface.

4. Billion Laughs — Denial of Service

Nested entity expansion causes exponential memory growth:

xml
<!DOCTYPE lolz [
  <!ENTITY lol "lol">
  <!ENTITY lol2 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
  <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">
]>
<root>&lol9;</root>

A few hundred bytes expand to multiple gigabytes, exhausting heap memory and crashing the JVM or process. Unlike other XXE variants, this is a pure availability attack — no data is exfiltrated, but the service goes down.

XXE Attack Impact Distribution

The chart below shows approximate impact category distribution based on vulnerability research and penetration test findings reported across the security community. Local file read and SSRF dominate because they directly yield high-value credentials and internal access.

pie title XXE Impact Categories "Local File Read" : 38 "SSRF to Internal Network" : 25 "Blind XXE Data Exfiltration" : 20 "Denial of Service" : 10 "Internal Port Scanning" : 7
#4XXE in OWASP Top 10 2017 — one of the most prevalent web app flaws (OWASP 2017)
A05Category XXE merged into Security Misconfiguration — OWASP Top 10 2021 (OWASP 2021)
USD 4.88MGlobal average cost of a data breach in 2024 (IBM Cost of a Data Breach 2024)

Know your vulnerabilities before attackers do

Run a free VAPT scan — takes 5 minutes, no signup required.

Book Your Free Scan

High-Risk Entry Points in Indian Enterprise Applications

🚨
DANGER
SAML-based Single Sign-On is one of the highest-impact XXE vectors. The SAML assertion is XML — if the Identity Provider or Service Provider parses the SAMLResponse without disabling external entities, an attacker can inject an XXE payload and read server files or trigger SSRF before authentication even completes. Indian banks, NBFCs, and government portals using SAML for employee SSO are common targets.

Beyond SAML, Indian enterprise apps carry additional risk at these surfaces:

    1. SOAP Web Services — Legacy banking APIs, insurance integrations, and e-governance systems still use SOAP. Every endpoint that deserialises a SOAP envelope is an XXE entry point if the parser is not hardened.
    2. Document Upload Endpoints — DOCX, XLSX, PPTX, and ODT files are ZIP archives containing XML files. Uploading a crafted .docx to an HR portal, contract management system, or KYC upload flow triggers XXE when the server unzips and parses document internals.
    3. SVG File Uploads — SVG is XML. Any image upload endpoint that accepts SVG and performs server-side rendering or metadata extraction is vulnerable.
    4. REST APIs with Content-Type: application/xml — Developers sometimes add XML as an alternative to JSON for compatibility with older clients. These endpoints are often under-tested because the team thinks of them as secondary.

Parser Configurations — Vulnerable vs Hardened

Language / ParserVulnerable DefaultSecure Setting
Java DocumentBuilderFactoryExternal entities enabled by defaultsetFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
Java SAXParserFactoryExternal entities enabled by defaultsetFeature("http://xml.org/sax/features/external-general-entities", false)
Java XMLInputFactoryEntity resolution enabledsetProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false)
Python xml.etreeNo external entities; vulnerable to Billion LaughsUse defusedxml library as a drop-in replacement
Python lxmlExternal entities enabled by defaultPass resolve_entities=False to the parser
PHP SimpleXMLSafe unless LIBXML_NOENT flag is passedRemove LIBXML_NOENT from all simplexml_load_* and DOMDocument::loadXML calls
.NET XmlDocumentXmlUrlResolver set by defaultSet XmlResolver = null explicitly before loading
Ruby NokogiriEntities enabled before v1.5.4; version-dependentUse Nokogiri::XML::ParseOptions::NONET to block network access
⚠️
WARNING
Updating your XML library version does not automatically harden it. Most parsers maintain backward-compatible defaults that leave external entity resolution enabled for older applications. You must explicitly configure the parser in code — a version bump alone is not a fix.

How to Fix XXE Vulnerabilities

Disable DTD Processing Entirely

The safest approach: reject any XML that contains a DOCTYPE declaration.

java
// Java — DocumentBuilderFactory
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
DocumentBuilder builder = dbf.newDocumentBuilder();

If your application legitimately uses DOCTYPE (for example, in SAML assertions), disable only external entities rather than all DOCTYPE declarations:

java
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);

Enable FEATURE_SECURE_PROCESSING

XMLConstants.FEATURE_SECURE_PROCESSING activates a bundle of security restrictions, including entity expansion limits:

java
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);

Make this your first change — then layer explicit entity disabling on top of it.

Use defusedxml for Python

python
import defusedxml.ElementTree as ET
tree = ET.parse(untrusted_xml_file)

defusedxml patches all standard library XML parsers to be safe. It rejects external entities, DTD processing, and Billion Laughs by default. Install it as a hard dependency in any Python service that processes XML.

Validate Against a Strict Schema

Do not parse raw XML from untrusted sources without schema validation. Use an XML Schema Definition (XSD) that explicitly disallows custom entity declarations. Reject any XML containing a DOCTYPE that your application's schema does not require.

Migrate Away from XML Where Possible

If you control the API contract, migrate endpoints to JSON. JSON has no concept of entity references or DTDs, eliminating the entire attack class. Every legacy XML endpoint converted to JSON is a permanent risk reduction.

💡
TIP
During a penetration test, testers probe every XML-accepting endpoint including file upload handlers, SAML POST parameters, and SOAP bodies. Run a dynamic scan against your staging environment with payloads targeting file:///etc/passwd and OOB callbacks to confirm your parser is hardened before those testers do. For a detailed reference on XXE payloads and detection techniques, PortSwigger's XXE research and the OWASP XXE Prevention Cheat Sheet are the most comprehensive freely available resources.

XXE and Indian Regulatory Exposure

The Digital Personal Data Protection (DPDP) Act 2023 requires organisations to implement reasonable security safeguards to protect personal data. An XXE vulnerability that lets an attacker read configuration files containing database credentials — or pivot via SSRF to an internal data store holding customer records — directly implicates that obligation. The liability exposure is real: regulators will ask whether industry-standard vulnerability assessments were conducted. An untested XML endpoint is a gap that is hard to justify in a post-breach review.

For fintech firms under RBI's IT and Cybersecurity Framework, and for SEBI-regulated entities under CSCRF, application-layer vulnerabilities are expected to be covered in mandatory security assessments. A successful XXE exploit chain reaching cloud credentials is also likely a reportable incident under CERT-In's mandatory 6-hour notification directive (April 2022), given that it constitutes unauthorised access to an IT system. Understand how your data handling obligations map to these requirements at the DPDP compliance resource.

For authoritative CVE records on XXE vulnerabilities across Java frameworks, SAML libraries, and document processing libraries, the NIST National Vulnerability Database catalogues hundreds of confirmed cases — a strong argument for running automated scans against your production attack surface.

What to Expect During an XXE-Focused Assessment

When Dhisattva AI Pvt Ltd performs a web application security assessment, XXE testing covers the following test cases as standard:

    1. Inject a DOCTYPE with a SYSTEM entity pointing to file:///etc/passwd in every XML-accepting endpoint
    2. Submit crafted SAML assertion POST bodies with embedded XXE payloads and observe responses
    3. Upload crafted DOCX, XLSX, and SVG files with malicious entity declarations inside document XML components
    4. Use out-of-band techniques with interactsh callbacks for blind XXE detection where responses give no visible output
    5. Test Billion Laughs resistance by submitting deeply nested entity definitions and measuring parser timeout or crash behaviour
    6. Test SSRF reachability to cloud metadata endpoints from identified XXE injection points
Book a free automated VAPT scan to identify XXE and other OWASP Top 10 vulnerabilities across your web application stack before attackers find them. See more security research and practical guides on the Bachao.AI blog.
🎯Key Takeaway
XXE injection exploits the XML parser's own legitimate functionality — no memory corruption or exploitation framework required. Disabling DOCTYPE declarations (or at minimum, external entity resolution) in your XML parser configuration eliminates the entire attack class. Default parser settings in Java, PHP, and .NET are unsafe for untrusted input. One misconfigured parser on a SAML endpoint, a file upload handler, or a legacy SOAP service is enough for an attacker to read server credentials and pivot to full infrastructure access.

Frequently Asked Questions

What is XXE injection in simple terms?
XXE (XML External Entity) injection is a vulnerability where an attacker embeds a malicious entity reference inside XML input. The server's XML parser fetches the referenced resource — a local file, an internal API, or an attacker-controlled server — and returns or leaks the content. No account credentials are required on the attacker's side, only the ability to send XML to an endpoint.
Which Java parsers are vulnerable to XXE by default?
DocumentBuilderFactory (DOM), SAXParserFactory (SAX), XMLInputFactory (StAX), and JAXB all enable external entity resolution in their default configurations. You must explicitly set parser features to disable DOCTYPE declarations or external entity loading. The OWASP XXE Prevention Cheat Sheet provides copy-paste hardening code for each parser family.
Can XXE be triggered through file uploads?
Yes. DOCX, XLSX, PPTX, and ODT files are ZIP archives containing internal XML files. An attacker crafts a malicious file, uploads it to any endpoint that processes document internals — HR portals, contract management systems, KYC upload flows — and the XXE fires when the server parses the embedded XML. SVG files are also XML and carry the same risk when accepted by image upload endpoints that perform server-side processing.
What is blind XXE and how is it detected?
Blind XXE occurs when the server does not return the parsed entity value in the HTTP response, making the data leak invisible in normal traffic. Detection relies on out-of-band techniques: the malicious entity triggers a DNS lookup or HTTP callback to an attacker-controlled listener, confirming the vulnerability exists even without visible output. Burp Collaborator and the open-source interactsh platform are the standard tools for catching these callbacks during penetration testing.
Is XXE still a risk in modern frameworks?
Yes. Many modern frameworks delegate XML parsing to underlying libraries that default to unsafe settings. Spring (Java), Laravel (PHP with SimpleXML), and .NET's DataContractSerializer have all had XXE-related vulnerabilities reported in recent years. The risk is highest in older Java middleware, SAML authentication libraries, and any Python code that uses the standard xml.etree module without the defusedxml patch applied.
How does XXE relate to SSRF and cloud credential theft?
XXE can directly trigger SSRF by pointing the external entity to an HTTP URL instead of a local file. The XML parser issues an HTTP request to the target URL from within the server's network, bypassing perimeter controls. In AWS environments, the target is typically the EC2 instance metadata endpoint, which returns temporary IAM role credentials without authentication — giving the attacker full programmatic access to the cloud account.
BR

Bachao.AI Research Team

Cybersecurity Research

AI-powered security research and threat intelligence from the Bachao.AI team. Covering the latest vulnerabilities, CVEs, and cybersecurity developments affecting Indian businesses.

Get cybersecurity insights for Indian SMBs

Weekly vulnerability alerts, DPDP compliance tips, and security guides. No spam — unsubscribe anytime.

We respect your privacy. Your email is never shared.

Find out if you're exposed to this class of threat

Free automated scan — risk score in under 2 hours. No credit card required.

Scan Your Attack Surface
Find your vulnerabilitiesStart free scan →