← Back to appsec.fyi

SQL Injection vs NoSQL Injection

Same concept, different databases. The payloads change but the root cause is identical.

SQL InjectionNoSQL Injection
Target databasesMySQL, PostgreSQL, MSSQL, Oracle, SQLiteMongoDB, CouchDB, Redis, Elasticsearch
Query languageSQLJSON objects, JavaScript, custom query syntax
Classic payload' OR 1=1--{"$gt": ""} or {"$ne": null}
Injection pointString concatenation in SQL queriesObject injection in query filters
Data exfiltrationUNION SELECT, blind techniquesOperator abuse ($regex, $where), blind techniques
DefenseParameterized queries / prepared statementsInput type validation, avoid $where, use ODM safely
ToolingsqlmapNoSQLMap, manual testing

Same disease, different symptoms

Both vulnerabilities exist because user input ends up inside a database query without proper handling. In SQL, that means string concatenation. In NoSQL (especially MongoDB), it often means passing user-controlled objects directly into query operators.

NoSQL injection in practice

The most common NoSQL injection targets MongoDB through JSON body manipulation. If a login endpoint passes the request body directly to db.find(), an attacker can send {"username": "admin", "password": {"$ne": ""}} and bypass authentication entirely. The $ne operator matches any non-empty password.

Why NoSQL injection gets overlooked

Developers assume "no SQL = no SQL injection." Wrong. The injection surface is different — you're injecting operators and objects instead of SQL syntax — but the impact is the same: authentication bypass, data exfiltration, and in some cases (MongoDB's $where with JavaScript) even code execution.

More comparisons: SSRF vs CSRF XSS vs CSRF AuthN vs AuthZ IDOR vs BOLA XSS Types SQLi vs NoSQLi SAST vs DAST Bug Bounty vs Pentest SBOM vs SLSA Validation vs Encoding