Code RoomSearch SQL injection
MediumPrep Room Coding #4408

Search SQL injection

Vibe & agenticSecurityDatabases & SQLMid–Senior~15 min

An AI generated this Flask search endpoint. It returns correct results in testing. A pentester drops a payload and dumps the whole users table. Identify the vulnerability and the precise fix — including the subtle reason the 'obvious' fix is also wrong here.

Implement
build_search_query(term: str, sort: str) → list[str]
Examples
in["django","title"]out["SELECT id, title FROM posts WHERE title LIKE ? ORDER BY title ASC","%django%"]
in["a%' UNION SELECT password, email FROM users -- ","created_at"]out["SELECT id, title FROM posts WHERE title LIKE ? ORDER BY created_at ASC","%a%' UNION SELECT password, email FROM users -- %"]
in["ai","id:desc"]out["SELECT id, title FROM posts WHERE title LIKE ? ORDER BY id DESC","%ai%"]
What a strong answer looks like

Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it (tests, edge cases, reading critically), and how you’d re-prompt or decompose to get it right.

0:00 of about 15 min

Vibe & agentic: describe the solution in plain language (or narrate it) and the coach grades your approach.

Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.