Code RoomORDER BY column injection
HardPrep Room Coding #2183

ORDER BY column injection

Code reviewSecurityDatabases & SQLSenior–Staff~20 min

Review this Python function that lists products with client-controlled sorting.

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 list_products(sort_col, direction):
2 # parameterized values are safe, but we also sort dynamically
3 sql = f"SELECT id, name, price FROM products ORDER BY {sort_col} {direction}"
4 cur.execute(sql, ())
5 return cur.fetchall()
6 
7# called as list_products(request.args['sort'], request.args['dir'])
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.