Admir Dizdar

Admir Dizdar

Author

Published Date: March 7, 2022

Estimated Read Time: 9 minutes

XXE Attacks: Types, Code Examples, Detection and Prevention

Table of Contents

  1. What Is an XXE Attack?
  2. What Is the Impact of XXE Injections?
  3. Types of XXE Attacks
  4. How Do XXE Attacks Work?
  5. XXE Attack Examples
  6. How to Detect XXE Attacks
  7. XXE Attack Prevention
  8. How XXE Attacks Work: A Step-by-Step Breakdown
  9. Typical Targets and Payload Examples
  10. Detecting XXE Vulnerabilities in Your Codebase
  11. Defensive Strategies: XML Parsers and Secure Configuration
  12. Testing for XXE

What Is an XXE Attack?

XXE (XML External Entity Injection) is a web-based vulnerability that enables a malicious actor to interfere with XML data processes in a web application. 

It often enables visibility of the files on an application server’s file system and interacts with a backend or external system that the application itself has access to. In some scenarios, the attacker might take an XXE attack a step further by exploiting the XXE attack payload to implement SSRF (Server-Side Request Forgery) in order to compromise backend infrastructure, such as the underlying server.

What Is the Impact of XXE Injections?

XXE injections can have significant impacts on organizations and individuals, including:

  • Data theft: XXE injections can allow attackers to extract sensitive data, such as passwords, confidential documents, or personal information, from a target system.
  • System compromise: XXE injections can be used to gain unauthorized access to systems and data, allowing attackers to execute malicious code, install malware, or steal sensitive data.
  • Denial of Service (DoS) attacks: XXE injections can be used to launch DoS attacks, overwhelming target systems and making them unavailable to users.
  • Reputation damage: XXE injections can result in the loss of sensitive data and the compromise of systems, which can damage an organization’s reputation and impact customer trust.
  • Increased risk of future attacks: XXE injections can create a foothold for attackers within a target system, making it easier for them to carry out additional attacks in the future.

Classification of XXE Attacks

There are several kinds of XXE attacks, including:

  • Billion Laughs Attack: This type of attack uses a maliciously constructed XML document that contains nested entity references to cause a buffer overflow and denial of service attack.
  • OOB (Out-of-Band) Data Retrieval: This attack allows an attacker to retrieve sensitive information from the target system by causing the XML parser to access external resources, such as files or network services, on behalf of the attacker.
  • Server-Side Request Forgery (SSRF): This type of attack is similar to OOB data retrieval but allows an attacker to send requests to internal network resources from the context of the target system, potentially allowing access to sensitive information or functionality.
  • Internal Entity Injection: This attack involves injecting internal entity definitions into an XML document, which can be used to interfere with the processing of XML data or extract sensitive information.
  • Blind XXE: This type of attack is similar to OOB data retrieval but doesn’t require the attacker to see the results of the attack. Instead, it relies on exploiting side-effects, such as causing a delay in processing time or consuming resources.

How Do XXE Attacks Work?

XML is an extremely popular format used by developers to transfer data between the web browser and the server. 

XML requires a parser, which is often where vulnerabilities are introduced. XXE enables the attacker to define entities defined based on the content of a URL or file path. When the server reads the XML attack payload, it parses the external entity, merges it into the final document, and returns it to the user with the sensitive data inside. 

XXE attacks can also be leveraged by an attacker to perform an SSRF attack and compromise the server.

Learn more in our detailed guide to xxe prevention.

XXE Attack Examples

Have a look at the examples below from our friends at OWASP:

Accessing a Local Resource that Might Return an Error


   
   ]>
&xxe;

Related content: Read our guide to xxe attack.

Remote Code Execution (RCE)

If fortune is on our side, and the PHP “expect” module is loaded, we can get RCE. Let’s modify the payload


  [
   ]>

  `&xxe;`
  `mypass`

Disclosing /etc/passwd or Other Target Files


  
  ]>
&xxe;

  
  ]>
&xxe;

  
  ]>
&xxe;

  
  ]>
&xxe;

How to Detect XXE Attacks

Detection of XXE attacks can be performed in a few ways:

  • Manually: This involves manually reviewing XML input files, server logs, and network traffic to identify any potential XXE attacks. This can be challenging because it requires expertise in understanding how XML parsers work and the various types of XXE attacks, as well as a good understanding of the specific system being monitored.
  • Using SCA tools: Static Code Analysis (SCA) tools can be used to scan code and identify any potential XXE vulnerabilities before the code is deployed. These tools can help identify common patterns in code that could lead to XXE attacks and provide suggestions for remediation.
  • Code scanning in early development stages: Integrating code scanning into the development process can help identify XXE vulnerabilities early in the development lifecycle. This can reduce the risk of these vulnerabilities being exploited and minimize the potential impact of a successful attack.

Regardless of the method used, regular monitoring and testing is important to ensure that systems remain secure and free from XXE attacks.

XXE Attack Prevention

XXE vulnerabilities commonly appear in web applications because the library that parses XML supports XML features, which could be dangerous and are enabled by default. Disabling these features is the most straightforward and effective approach to preventing an XXE attack.

Disable external entities resolution and XInclude support either in the configuration or programmatically, by overriding the default behaviors. 

How XXE Attacks Work: A Step-by-Step Breakdown

For a better understanding of the XXE attack, it is necessary to discuss a real XXE example rather than explaining the theory right away. In fact, most of such vulnerabilities arise due to the way applications consume XML and parse it without any restrictions.

As an example, the attacker uses the XML message, which contains an entity pointing at something confidential on the server, for instance, a local file. During processing of this XML message, the parser extracts data from the specified entity and adds it to the result.

The problem with XXE attacks lies in their seemingly harmless nature. For an application, this process does not differ from parsing any other XML messages. But in fact, some data are revealed during this process.

Typical Targets and Payload Examples

When you look at an XXE example, the target is usually something the server already has access to. Attackers are not breaking into the server directly. They are making the server show its data.

A common payload will try to read files like /etc/passwd on Linux systems. Others might target configuration files, API keys, or internal endpoints. Some attackers even use XXE to make requests to services that are normally not accessible from outside.

The XXE payload itself is not always complicated. It just defines an entity and references it somewhere in the XML. Small changes can make a big difference, especially when attackers try different encodings or bypass techniques. It is less about how complicated the XXE payload is, more about how persistent the attackers are and what the parser will allow the XXE payload to do.

Detecting XXE Vulnerabilities in Your Codebase

Detecting XXE issues can be tricky, especially when using automated scans. A good way to start is with an XXE example to see how your application reacts.

If your system takes XML, try sending a payload with an entity and check the response. Does it give back data you didn’t expect? Does it make calls to systems? These are clues, but they are important.

Developers should also look at how XML parsers are set up in the code. Often, the vulnerability is there because the default settings were not changed. Tools can help find settings, but a manual review is still crucial. The goal is not just to find XXE but to understand how your application handles XML in real-life situations.

Defensive Strategies: XML Parsers and Secure Configuration

Preventing XXE attacks is really about how you handle XML from the start. If you look at any XXE example, the problem usually begins with the parser allowing entities.

The best way to be safe is to turn off external entity processing. Most new libraries have this option. It is not always turned on by default. This is where the problems start to happen.

It is also an idea to use simpler data formats like JSON when you can because they do not have the same risks as XML. If you have to use XML, it is very important to keep the parser configurations strict. Limiting what files can be accessed, turning off DTDs, and not using features you do not need can make a difference.

At the end of the day, XXE attacks are not about using exploits. They are about small mistakes, in how things are set up, that get missed. XXE attacks are a problem because of these mistakes.

Testing for XXE

XXE attacks represent a serious risk to organizations. The good news is that they can be prevented easily by using and properly configuring a good XML parser, whilst ensuring input validation, proper error handling and minimizing filesystem permissions.

You can easily test your applications for XXE and other vulnerabilities with a modern DAST security scanner, whether integrated across your development pipelines to scan every build or merge to master or before you release them to production – Try Bright DAST for free to achieve just that.

Stop testing.

Start Assuring.

Join the world’s leading companies securing the next big cyber frontier with Bright STAR.

Our clients:

More

Threats and Vulnerabilities

When MCP Trust Boundaries Break: 3 Silent but Critical Risks

MCP servers are designed to enforce structure. They define typed tools, document expected inputs, and separate public access from admin...
Admir Dizdar
April 6, 2026
Read More
Threats and Vulnerabilities

From MCP Tool Call to Code Execution: 3 Exploitation Patterns

MCP endpoints are often described as a safe abstraction layer for AI agents - a way to define clear boundaries...
Admir Dizdar
April 6, 2026
Read More
Threats and Vulnerabilities

WAF Bypass Reality Check: Why a Better DAST Still Matters Even If You Have a WAF

Most security teams have had this conversation at some point: “We already have a WAF in front of the app....
Admir Dizdar
March 23, 2026
Read More
Threats and Vulnerabilities

How MCP Endpoints Leak Sensitive Data: 3 High-Impact Paths

MCP servers are often presented as a clean interface for AI agents to discover tools and interact with applications. That...
Admir Dizdar
March 20, 2026
Read More