← All scars

scar-002 · scar

SQL built by string concatenation

A query was assembled by joining user input into the SQL string, which allows SQL injection.

criticalcaptured Oct 5from commit a3a2995repeated ×1

Before and after

Before · the mistake
1db.query("SELECT * FROM users WHERE id = " + id)
After · the rule
1Use placeholders: db.query("SELECT * FROM users WHERE id = ?", [id])

How it’s detected

/(SELECT|INSERT|UPDATE|DELETE)\b.*["'\x60]\s*\+\s*[A-Za-z_]/i

Times it came back

src/db/orders.js:8Oct 8, 1:15 PM

A new orders query was built by concatenating the id into the SQL string.