Menu

πŸ’‰ SQL Injection: Where Placeholders Can't Go (ORDER BY, IN, LIKE)
πŸ“°

πŸ’‰ SQL Injection: Where Placeholders Can't Go (ORDER BY, IN, LIKE)

DEV Community: appsecΒ·Krishna KumarΒ·1 day ago
#Gxsyimt2
#devtoappsec#devto#dev#self#name
Reading 0:00
15s threshold

"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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.