CWE-652: Improper Neutralization of Data within XQuery Expressions
Also known as: XQuery Injection
The product uses external input to dynamically construct an XQuery expression used to retrieve data from an XML database, but it does not neutralize or incorrectly neutralizes that input.
Last updated
Overview
CWE-652 (Improper Neutralization of Data within XQuery Expressions) is a base-level software weakness catalogued by MITRE in the Common Weakness Enumeration (CWE). It describes a recurring type of mistake that can lead to exploitable security vulnerabilities.
Real-world CVEs
2 recorded CVEs are caused by CWE-652 (Improper Neutralization of Data within XQuery Expressions). The highest-severity and most recent are shown first.
Common consequences
What can happen when CWE-652 is exploited.
Read Application Data
Affects: Confidentiality
An attacker could modify the structure of the query to control what information is selected by the XML database, then use that ability to control application flow, modify logic, retrieve unauthorized data, or bypass important checks (e.g. authentication).
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
How to prevent it
Practical mitigations for CWE-652, grouped by where in the lifecycle they apply.
Use parameterized queries. This will help ensure separation between data plane and control plane.
Properly validate user input. Reject data where appropriate, filter where appropriate and escape where appropriate. Make sure input that will be used in XQL queries is safe in that context.
How to detect it
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
Code examples
MITRE examples of the weakness in code.
An attacker may pass XQuery expressions embedded in an otherwise standard XML document. The attacker tunnels through the application entry point to target the resource access layer. The string below is an example of an attacker accessing the accounts.xml to request the service provider send all user names back. doc(accounts.xml)//user[name='*'] The attacks that are possible through XQuery are difficult to predict, if the data is not validated prior to executing the XQL.
Terminology & mappings
Alternate terms
- XQuery Injection
Mapped taxonomies
- WASC: XQuery Injection (46)
- Software Fault Patterns: Tainted input to command (SFP24)
Frequently asked questions
Common questions about CWE-652.
- What is CWE-652?
- The product uses external input to dynamically construct an XQuery 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-652?
- 2 recorded CVEs are attributed to CWE-652, including CVE-2023-28676 and CVE-2023-25015.
- How do you prevent CWE-652?
- Use parameterized queries. This will help ensure separation between data plane and control plane.
- How is CWE-652 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-652?
- Exploiting CWE-652 can lead to: Read Application Data.
- Is CWE-652 actively exploited?
- 2 recorded CVEs are caused by CWE-652; none are currently in CISA's KEV catalog of actively exploited flaws.
Sources
References
- MITRE CWE definition (CWE-652) (opens in a new tab)
- CWE-652 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.21). CVE associations are aggregated and kept current by RadicalNotion.AI.
Track CWE-652 CVEs
Get an alert when a new CWE-652 CVE affects your products, with AI-written analysis and remediation steps.