---
title: "CWE-643: Improper Neutralization of Data within XPath Expressions"
url: https://radicalnotion.ai/cwe/cwe-643
type: cwe
description: "The product uses external input to dynamically construct an XPath expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-643: Improper Neutralization of Data within XPath Expressions

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Incomplete
- **Likelihood of exploit:** High
- **CVEs with this as primary weakness:** 17
- **Of those, in CISA KEV:** 0
- **New in 2026:** 7
- **CWE catalog version:** 4.21

## Description

The product uses external input to dynamically construct an XPath expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input.

## Alternate terms

- XPath Injection

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Access Control | Bypass Protection Mechanism | An attacker can control the structure of the query, possibly causing unexpected data to be returned. This can be further used to control application flow (e.g., bypassing authentication). |
| Confidentiality | Read Application Data | By modifying the XPath query, an attacker could read restricted XML content by choosing which information is selected from the XML database. |

## Potential mitigations

### Implementation

Use parameterized XPath queries (e.g. using XQuery). This will help ensure separation between data plane and control plane.

### Implementation

Properly validate user input. Reject data where appropriate, filter where appropriate and escape where appropriate. Make sure input that will be used in XPath queries is safe in that context.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

Consider the following simple XML document that stores authentication information and a snippet of Java code that uses XPath query to retrieve authentication information:

Informative code:

```xml
<users>
    <user>
        <login>john</login>
        <password>abracadabra</password>
        <home_dir>/home/john</home_dir>
    </user>
    <user>
        <login>cbc</login>
        <password>1mgr8</password>
        <home_dir>/home/cbc</home_dir>
    </user>
</users>
```

Bad code:

```java
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression xlogin = xpath.compile("//users/user[login/text()='" + login.getUserName() + "' and password/text() = '" + login.getPassword() + "']/home_dir/text()");
Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File("db.xml"));
String homedir = xlogin.evaluate(d);
```

Attack code:

```
//users/user[login/text()='john' or ''='' and password/text() = '' or ''='']/home_dir/text()
```

## Real CVEs with this weakness (sample of 12 of 17)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-44962 | - | critical | 9.9 | - | No | 2026-05-29 |
| CVE-2026-9390 | XML::Sig versions before 0.71 for Perl allow XPath injection in ID lookup | critical | 9.1 | - | No | 2026-08-03 |
| CVE-2026-24343 | Apache HertzBeat: Uncontrolled Resource Consumption via Crafted XPath Expressions | high | 8.8 | - | No | 2026-02-10 |
| CVE-2024-39565 | Junos OS: J-Web: An unauthenticated, network-based attacker can perform XPATH injection attack against a device. | high | 7.7 | - | No | 2024-07-10 |
| CVE-2020-25162 | B. Braun SpaceCom, Battery Pack SP with Wi-Fi, and Data module compactplus | high | 7.5 | - | No | 2022-04-14 |
| CVE-2026-40699 | BIG-IP Configuration utility vulnerability | high | 7.1 | - | No | 2026-05-13 |
| CVE-2026-114442 | Apache HertzBeat: incomplete XPath expression validation in aliasFields | medium | 6.5 | - | No | 2026-11-03 |
| CVE-2026-11864 | Multiple security vulnerabilities are addressed with IBM Cloud Pak for Business Automation iFixes for August 2026. | medium | 6.5 | - | No | 2026-09-15 |
| CVE-2023-36429 | Microsoft Dynamics 365 (On-Premises) Information Disclosure Vulnerability | medium | 6.5 | - | No | 2023-10-10 |
| CVE-2023-36433 | Microsoft Dynamics 365 (On-Premises) Information Disclosure Vulnerability | medium | 6.5 | - | No | 2023-10-10 |
| CVE-2023-24922 | Microsoft Dynamics 365 (On-Premises) Information Disclosure Vulnerability | medium | 6.5 | - | No | 2023-03-14 |
| CVE-2025-11844 | XPath Injection in Hugging Face Smolagents search\_item\_ctrl\_f Function | medium | 5.4 | - | No | 2025-10-22 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-91](https://radicalnotion.ai/cwe/cwe-91) | XML Injection |
| Parent | [CWE-943](https://radicalnotion.ai/cwe/cwe-943) | Improper Neutralization of Special Elements in Data Query Logic |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| WASC | XPath Injection | 39 | - |
| Software Fault Patterns | Tainted input to command | SFP24 | - |

## Frequently asked questions

### What is CWE-643?

The product uses external input to dynamically construct an XPath expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input.

### What CVEs are caused by CWE-643?

17 recorded CVEs are attributed to CWE-643, including CVE-2026-44962, CVE-2026-9390 and CVE-2026-24343.

### How do you prevent CWE-643?

Use parameterized XPath queries (e.g. using XQuery). This will help ensure separation between data plane and control plane.

### How is CWE-643 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-643?

Exploiting CWE-643 can lead to: Bypass Protection Mechanism, Read Application Data.

### Is CWE-643 actively exploited?

17 recorded CVEs are caused by CWE-643; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/643.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-643). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
