Web SecurityWeb Security · Lesson 05
SQL & NoSQL Injection
How injection works, blind variants and parameterised queries.
Video tutorialTrack course · freeCodeCamp
Speed
Transcript & captions
10/10
Injection occurs when user input is concatenated into a query so the data becomes part of the command. The classic result is authentication bypass or full database dumping.
The bugjs
// VULNERABLE
const sql = "SELECT * FROM users WHERE email = '" + email + "'";
// email = "' OR '1'='1" -> the WHERE clause is always true
// SAFE - parameterised, input can never become syntax
db.query('SELECT * FROM users WHERE email = $1', [email]);- Error-based: the database error message leaks structure.
- Union-based: append a UNION SELECT to read other tables.
- Blind boolean: the page changes subtly with true/false conditions.
- Time-based blind: use a sleep to infer answers from response delay.
- NoSQL: operator injection such as sending an object instead of a string.
Defence: always parameterise or use an ORM's binding, apply least-privilege database users, validate types, and never surface raw database errors to users.
Knowledge check
0/2 answeredThe primary fix for SQL injection is...
Time-based blind injection infers data from...