"We use parameterized queries everywhere" is the most common answer to "are you safe from SQL injection?". It's usually almost true. The WHERE clauses are bound, the INSERT s are bound, and then there's a product list with a sort dropdown, and one line that looks like this:
sql = f "SELECT id, name, price FROM products ORDER BY {sort}"
Enter fullscreen mode
Exit fullscreen mode
Nobody wrote that out of laziness. They wrote it because the placeholder didn't work there. This post is a fix guide for those spots: the parts of a query a placeholder can't carry, what to do instead, and tests that prove the fix holds. Everything here runs against a local in-memory database. Only test what you own or are authorized to test.
What a placeholder actually binds
A placeholder carries a value . It doesn't carry SQL.β¦