Review how the input is added to this SQL statement.
def find_user(cursor, username):
query = "SELECT id, name FROM users WHERE name = '" + username + "'"
return cursor.execute(query).fetchone()
The value comes from outside the program. Prefer the database driver’s parameter binding instead of building SQL with string concatenation.
What is the safest way to use username in this query?
The database treats the supplied value as data rather than executable SQL.
Filtering a few characters is fragile and does not reliably prevent SQL injection.
URL encoding is unrelated to SQL parsing and does not make string concatenation safe.
Manual escaping is driver- and database-dependent; parameter binding is safer.
Why it matters: Parameterized queries keep user data separate from executable SQL.