1 What is NoSQL Injection?
NoSQL databases like MongoDB use query objects instead of SQL strings, but they are still vulnerable to injection when user-supplied data is used directly in query operators.
Vulnerable example (Node.js + MongoDB):
// Attacker sends: { "password": { "$gt": "" } }
const user = await db.collection("users").findOne({
username: req.body.username,
password: req.body.password // injected operator!
});The $gt operator makes the password condition always true, bypassing authentication. Other operators like $where execute arbitrary JavaScript server-side, enabling data exfiltration.
Tautology attack example:
{ "username": { "$gt": "" }, "password": { "$gt": "" } }This query returns the first document in the collection, effectively logging in as any user without knowing credentials.