---
updatedAt: 2025-08-04T20:52:49.000Z
agentTools:
  projectIndex: https://docs.brightsec.com/llms.txt
---

# XML External Entity (XXE)

<HTMLBlock>{`
<table id="simple-table">
   <style>
 #simple-table {
    border-collapse: separate;
    width: 100%;
    display: block;
    display: table;
  }
#simple-table th {
    padding: 1.5%;
    text-align: left;
    vertical-align: text-top;
    background-color: #B2D6DA;
  </style>
  <body>
    <tr>
        <th><strong>Details</strong></th>
    </tr>
</table>
  </body>
`}</HTMLBlock>

<HTMLBlock>{`
Severity: <b><font color="#b81a46">Critical</font></b><br />
Test Name: <b>XML External Entity (XXE)</b><br />
Test ID: <b>xxe</b>
`}</HTMLBlock>

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Description</strong></th>
    </tr>
</table>
`}</HTMLBlock>

XML External Entity vulnerability allows an attacker to upload an XML file with a reference to an external entity without validation. The attacker exploits weakly configured XML parsers, which process the XML code. The attack can lead to gaining confidential information and even to Remote Code Execution (RCE).

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Impact</strong></th>
    </tr>
</table>
`}</HTMLBlock>

The vulnerability may expose the application to the following attack vectors:

* Gain sensitive information
* Disclose internal content via HTTP(S) requests or launch a CSRF attack to any unprotected internal services
* Initiate SSRF attack in applications that use XML
* Modifying the content type of `application/x-www-form-urlencoded` to enable XXE with LFI
* Leveraging **XInclude** for `application/x-www-form-urlencoded` by injecting XML parameters with XXE
* Execute a malicious URL, possibly allowing the arbitrary code to be executed under the application account
* Cause denial of the services (DoS)

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Examples</strong></th>
    </tr>
</table>
`}</HTMLBlock>

**Example 1: Accessing a local resource**

```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE credentials [
    <!ELEMENT credentials (user, password)>
    <!ELEMENT user (#PCDATA)>
    <!ELEMENT password (#PCDATA)>
    <!ENTITY xxe SYSTEM  "file:///etc/passwd" >
]>
<credentials>
    <user>&xxe;</user>
    <password>mypass</password>
</credentials>
```

**Example 2: Remote code execution**

```xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE foo [ 
    <!ELEMENT foo ANY >
    <!ENTITY xxe SYSTEM "expect://id" >
]>
<credentials>
    <user>&xxe;</user>
    <password>mypass</password>
</credentials>
```

**Example 3: XXE to perform SSRF attack**

```Text XML
<?xml version=”1.0" encoding=”UTF-8"?>
<stockCheck><productId>3301</productId></stockCheck>
```

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Locations</strong></th>
    </tr>
</table>
`}</HTMLBlock>

The issue can be found in the **source code** on the **server side**.

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Remediation suggestions</strong></th>
    </tr>
</table>
`}</HTMLBlock>

1. Disable Document Type Declaration (DTD) completely.
2. If it is not possible to disable DTD completely, then external entities and external document type declarations must be disabled according to each specific parser.
   * PHP
   ```
   libxml_disable_entity_loader(true);
   ```
   * Java (Xerces)
   ```
   DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
   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/disallow-doctype-decl", true);
   ```

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>Classifications</strong></th>
    </tr>
</table>
`}</HTMLBlock>

* CWE-611
* CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:L

<HTMLBlock>{`
<table id="simple-table">
    <tr>
        <th><strong>References</strong></th>
    </tr>
</table>
`}</HTMLBlock>

* <https://cwe.mitre.org/data/definitions/611.html>
* [https://www.owasp.org/index.php/XML\_External*Entity*(XXE)\_Processing](https://www.owasp.org/index.php/XML_External_Entity_\(XXE\)_Processing)
* <https://brightsec.com/blog/xxe-vulnerability/>