NoSQL Injection
noun
say it: “noh-SEE-kwul in-JEK-shun” /noʊ ˈsikwəl ɪnˈdʒɛkʃən/
An attack that sneaks database query operators into a request, so a document database runs a search the attacker controls.
What is NoSQL injection?
NoSQL injection is an attack where someone sends a query operator, such as { "$ne": null }, where the API expects plain text. If the API puts it straight into a filter, the database runs a search the attacker chose. Check that each value is text before using it.
// POST /reset-password with { "email": { "$ne": null } }
const user = await users.findOne({ email: req.body.email });
// finds the first user in the collection, not the one the caller named
In a sentence
- “A NoSQL injection slipped { "$ne": null } into the filter and found the first account in the collection.”
- “Checking that email is a string with Zod blocked the NoSQL injection in the coffee club's sign-in.”
Level: Freelancer · More MongoDB terms at this level
Updated