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

Where the habit breaksdriver's safe API isusedbut the SQL argumentitself was built wit…looks safe, is not
Where the habit breaks

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
MistakeWhat it looks likeWhy it fails
Building the SQL string firstcur.execute(f"... WHERE email = '{email}'")The value is already inside the "SQL text" argument before execute() ever sees it
String-joining identifierscur.execute(f"SELECT * FROM {table}")Table/column names cannot be bound; needs an allowlist instead (see earlier lesson)
Mixing bound and unbound partsOne placeholder used, but ORDER BY built from raw inputEvery dynamic part needs its own safe handling, not just one of them
Trusting an ORM's raw() blindlyORM.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...