Loading Depth Study
Preparing your workspace
SQL injection happens when untrusted input changes the intended structure of a SQL statement.
Building SQL queries by concatenating user input can allow an attacker to alter the query itself. Parameterized queries keep SQL structure separate from user-provided values. Database libraries, prepared statements, and query builders provide safe ways to pass values. Validation remains useful, but it does not replace parameterization because even valid-looking input can be unsafe when placed into SQL incorrectly.
A login or search endpoint should use a parameterized query instead of inserting an email or search string directly into a SQL statement.
const result = await db.query( 'SELECT id, name FROM users WHERE email = $1', [email] );
The email is passed as a parameter and cannot change the SQL statement structure.