Code RoomSQL injection in sort column
MediumPrep Room Coding #1832

SQL injection in sort column

Code reviewSecurityDatabases & SQLMid–Senior~20 min

Review this Python data-access function used by a search endpoint.

What a strong answer looks like

Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.

0:00 of about 20 min
Mark a line and say what kind of problem it is.0 findings
1def search_users(conn, name, sort_col):
2 cur = conn.cursor()
3 query = (
4 "SELECT id, email FROM users "
5 "WHERE name LIKE '%%%s%%' "
6 "ORDER BY %s" % (name, sort_col)
7 )
8 cur.execute(query)
9 return cur.fetchall()
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.