Queries and indexes Required
Pass values as parameters
Send every value as a query parameter. Never build SQL by joining strings with input.
How to do it
Use placeholders such as $1, ? or %s in the driver or query builder. Placeholders hold values only. Table names, column names and sort directions cannot be parameters, so map them from a fixed allow-list in code. ORMs are safe until you pass input to their raw SQL functions. The SQL injection rule shows the attack this stops.
Example
// Bad
db.query(`SELECT id FROM customers WHERE email = '${email}'`);
// Good
db.query('SELECT id FROM customers WHERE email = $1', [email]);
# Bad
cursor.execute(f"SELECT id FROM customers WHERE email = '{email}'")
# Good
cursor.execute("SELECT id FROM customers WHERE email = %s", (email,))
// Good in PHP with PDO
$statement = $pdo->prepare('SELECT id FROM customers WHERE email = ?');
$statement->execute([$email]);
How to check
Search the code for SQL built with string joins or template strings that hold variables. None remain.
For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/queries-and-indexes/parameters.