Home / Learn Secure SQL / Common Parameter-Binding Mistakes
Common Parameter-Binding Mistakes
A checklist of the ways developers accidentally undo the safety.
The short versionA checklist of the ways developers accidentally undo the safety.
Theory in plain words
The basic idea
Even when a team "uses prepared statements", a few specific habits can quietly reintroduce the core problem: building part of the SQL string with the value first, then passing that whole string as if it were the fixed SQL text.
Why this comes up
These mistakes are worth memorising because they look, at a glance, like correct code using a prepared statement API.
The mechanics
Review every query for these specific patterns during code review, not just for the presence of a driver's execute() call.
Where it is used
- Web application code review
- Backend development
- Database administration
| Mistake | What it looks like | Why it fails |
|---|---|---|
| Building the SQL string first | cur.execute(f"... WHERE email = '{email}'") | The value is already inside the "SQL text" argument before execute() ever sees it |
| String-joining identifiers | cur.execute(f"SELECT * FROM {table}") | Table/column names cannot be bound; needs an allowlist instead (see earlier lesson) |
| Mixing bound and unbound parts | One placeholder used, but ORDER BY built from raw input | Every dynamic part needs its own safe handling, not just one of them |
| Trusting an ORM's raw() blindly | ORM.raw(f"... = '{value}'") | raw() is still plain SQL text underneath; its own parameter argument must be used |
Quick check
1. A query that "uses" execute() can still be unsafe if...
The string-building happened before execute() was even called.