Description
The product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the intended logic of the query.
Depending on the capabilities of the query language, an attacker could inject additional logic into the query to: The ability to execute additional commands or change which entities are returned has obvious risks. But when the product logic depends on the order or number of entities, this can also lead to vulnerabilities. For example, if the query expects to return only one entity that specifies an administrative user, but an attacker can change which entities are returned, this could cause the logic to return information for a regular user and incorrectly assume that the user has administrative privileges. While this weakness is most commonly associated with SQL injection, there are many other query languages that are also subject to injection attacks, including HTSQL, LDAP, DQL, XQuery, Xpath, and "NoSQL" languages.
Potential Impact
Confidentiality, Integrity, Availability, Access Control
Bypass Protection Mechanism, Read Application Data, Modify Application Data, Varies by Context
Demonstrative Examples
...string userName = ctx.getAuthenticatedUserName();string query = "SELECT * FROM items WHERE owner = '" + userName + "' AND itemname = '" + ItemName.Text + "'";sda = new SqlDataAdapter(query, conn);DataTable dt = new DataTable();sda.Fill(dt);...SELECT * FROM items WHERE owner = <userName> AND itemname = <itemName>;name' OR 'a'='aSELECT * FROM items WHERE owner = 'wiley' AND itemname = 'name' OR 'a'='a';OR 'a'='aSELECT * FROM items;context = new InitialDirContext(env);String searchFilter = "StreetAddress=" + address;NamingEnumeration answer = context.search(searchBase, searchFilter, searchCtls);<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>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);//users/user[login/text()='john' or ''='' and password/text() = '' or ''='']/home_dir/text()Detection Methods
- Automated Static Analysis High — 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 sea
Real-World CVE Examples
| CVE ID | Description |
|---|---|
| CVE-2024-50672 | NoSQL injection in product for building eLearning courses allows password resets using a query processed by the Mongoose find function |
| CVE-2021-20736 | NoSQL injection in team collaboration product |
| CVE-2020-35666 | NoSQL injection in a PaaS platform using a MongoDB operator |
| CVE-2014-2503 | Injection using Documentum Query Language (DQL) |
| CVE-2014-2508 | Injection using Documentum Query Language (DQL) |
Related Weaknesses
Frequently Asked Questions
What is CWE-943?
CWE-943 (Improper Neutralization of Special Elements in Data Query Logic) is a software weakness identified by MITRE's Common Weakness Enumeration. It is classified as a Class-level weakness. The product generates a query intended to access or manipulate data in a data store such as a database, but it does not neutralize or incorrectly neutralizes special elements that can modify the inten...
How can CWE-943 be exploited?
Attackers can exploit CWE-943 (Improper Neutralization of Special Elements in Data Query Logic) to bypass protection mechanism, read application data, modify application data, varies by context. This weakness is typically introduced during the Implementation phase of software development.
How do I prevent CWE-943?
Follow secure coding practices, conduct code reviews, and use automated security testing tools (SAST/DAST) to detect this weakness early in the development lifecycle.
What is the severity of CWE-943?
CWE-943 is classified as a Class-level weakness (High abstraction). It has been observed in 5 real-world CVEs.