NoSQL Injection
Cheatsheet for CTFs & web pentests. Based on PortSwigger Web Security Academy. Most examples target MongoDB (most common in the wild).
Two flavors:
- Syntax injection — break the query string (like classic SQLi but JS/JSON-flavoured).
- Operator injection — inject Mongo operators
(
$ne,$regex,$where, …) as nested JSON / bracketed params.
See also SQL Injection, Authentication (auth-bypass payloads), API Security.
Where to look
- Login forms with JSON body
(
{"username":"x","password":"y"}) - Anything with structured filters: search, category, sort, pagination, “advanced search”
- GraphQL backends sitting on Mongo
- Internal admin endpoints — often use
$wherewith raw JS - Password reset / forgot-password flows (token field hidden in user doc)
Detection
Fuzz string (URL / param):
'"`{
;$Foo}
$Foo \xYZ
JSON-encoded variant:
'\"`{\r;$Foo}\n$Foo \\xYZ
Single-character probes:
| Input | Look for |
|---|---|
' |
error / different response → string context |
" |
same, double-quoted context |
\ |
escape handling |
; } |
ends query block |
|