Node.js · Middle · Question 41 of 75

Why must SQL queries use parameters instead of string concatenation?

// Bad
db.query("SELECT * FROM users WHERE email = '" + email + "'");
// Good
db.query("SELECT * FROM users WHERE email = $1", [email]);

Explanation

ORMs and query builders parameterize for you, but raw queries built from strings are still vulnerable.

Further reading

Problem with a question

Node.js · Middle · question 41

Test yourself

Take the Node.js · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz