01Issue
Overview
NoSQL databases store and query data using formats that differ from SQL. NoSQL injection happens when untrusted input changes the structure or meaning of a database query instead of being treated as a simple value. For example, an endpoint expecting a username string may accept a nested object that the database driver interprets as a query operator. The correct test depends on the database and driver.
Common causes
- The endpoint accepts objects or arrays where it expects a string or number.
- Request data is merged directly into a query document.
- The application builds query strings or operators from user input.
- Validation checks the browser form but not the server-side JSON structure.
References: OWASP NoSQL Security Cheat Sheet ↗OWASP WSTG: NoSQL Injection Testing ↗CWE-943: Improper Neutralization in Data Query Logic ↗
02Examples
Illustrative JSON: the endpoint expects {"username":"reader"}. Compare it with {"username":{"$ne":""}} using a test dataset and observe the selected records. A changed result suggests the value may be interpreted as query structure; verify the server-side query and actual access policy before reporting impact.
03Impact
User-controlled input must reach a NoSQL query in a form the database or driver interprets as query structure. A strange response or accepted object is not proof; confirm that query behavior changed and that a protected result or decision was affected.
A confirmed issue may broaden search results, bypass a login condition, or alter data operations, depending on the query and database permissions. Do not claim authentication bypass or data modification unless the tested endpoint demonstrates it.
04Testing
Test cases
1. Check whether structured input changes a query decision
Compare a normal value with an unexpected object or array in a test dataset. Verify the selected records or authentication decision.
Example: A different response alone does not prove injection. Check whether the database interpreted input as query structure.
POST /api/search HTTP/1.1
Host: app.example.test
Content-Type: application/json
{"username":{"$ne":""}}
2. Check authentication query handling
Compare a normal failed test login with a request that changes a field’s type. Verify whether the server issues an authenticated session and inspect the query when logs or code are available.
Example: Use an incorrect password for the test account. A changed error or response is not proof of a login bypass.
POST /api/login HTTP/1.1
Host: app.example.test
Content-Type: application/json
{"username":{"$ne":""},"password":"incorrect"}
3. Review query construction across routes
Check filters, login, and update paths for direct merging of request objects into database queries. Separate a broadened search from an authentication bypass.
Example: Finding an operator in an error is a clue. Confirm the affected operation and actual access.
Testing references: OWASP NoSQL Security Cheat Sheet ↗OWASP WSTG: NoSQL Injection Testing ↗CWE-943: Improper Neutralization in Data Query Logic ↗
05Mitigation
Validate request schemas and require primitive values where the feature expects them. Build queries through the database driver’s value-binding APIs, allowlist permitted operators and fields, and do not merge arbitrary request objects into query documents. Keep database accounts limited to the operations the application needs.
Retest
Repeat primitive, object, array, and filter tests. Confirm unexpected structures are rejected and the query result remains within the intended records and permissions.