The Invisible Burglar: SQL Injection Explained (2026)
By Huzi
File #372 · 3 min read
SQL injection is the vulnerability that refuses to retire: it has lived in the OWASP Top 10's injection category for over two decades, not because the fix is missing but because string concatenation keeps creeping back into code. The fix is old, boring and total — and worth knowing cold.
The quick answer: SQL injection glues user input straight into a query string, so admin' -- can comment out a password check. The fix is total and boring: parameterized queries, where values bind as data and never as code. Every ORM parameterizes by default — the danger is its raw-query escape hatch.
The input trap
Take the world's most common login query:
SELECT * FROM users WHERE username = '$user' AND password = '$pass';
Whatever the visitor typed was glued straight into the statement. Type admin' -- as the username and the quote closes the string while the comment marker eats the remainder:
SELECT * FROM users WHERE username = 'admin' --' AND password = '...'
The password check simply ceases to exist. UNION variants dump whole tables into the page, blind variants extract data one true-or-false question at a time, and sqlmap automates all of it for whoever points it at your site.
The fix: parameterized queries
Never build SQL out of user input. Send the query as a blueprint and bind values strictly as data:
// Node.js with pg — safe
const result = await pool.query(
'SELECT id, username FROM users WHERE email = $1 AND active = $2',
[userEmail, true]
);
# Python with sqlite3 — safe
cursor = conn.execute(
'SELECT id, username FROM users WHERE email = ? AND active = ?',
(user_email, 1),
)
The database compiles the structure first and binds values second, so typing DROP TABLE users into the email field makes the system calmly search for a user with that literal name.
The ORM trap
Prisma, Django's ORM, SQLAlchemy and Eloquent parameterize by default — and every one of them offers a raw-query escape hatch. Sooner or later someone writes a raw query with template strings, and the door quietly reopens. The rule survives every framework: user input reaches raw SQL only as a bound parameter, never through interpolation.
Every trusted system has an escape hatch — the raw query in the ORM, the fine print in the fare. HTG Travels reads the hatch before you walk through it: what a ticket actually allows, and what it silently does not.
Layers behind the code
Give the application's database account only the permissions it truly needs — one user for reading, another for writing — so a successful injection cannot DROP or ALTER anything it finds. Keep the database off the public internet. Let a WAF such as ModSecurity or Cloudflare act as a tripwire.
| Layer | The control | What it stops |
|---|---|---|
| Code | Parameterized queries (pg, sqlite3) | Input treated as data, never SQL |
| ORM discipline | No raw queries with template strings | The quietly reopened door |
| Database rights | One read user, one write user | DROP and ALTER on success |
| Network | Database off the public internet | Direct outside probing |
| Perimeter | WAF — ModSecurity or Cloudflare | A tripwire before production |
| Testing | sqlmap against staging | The stranger's tool, run first |
Pro tip: Run sqlmap against a staging copy of your own site before a stranger runs it against production. The tool that breaks you is the same one that can warn you.
In Gaza, developers keep shipping careful, parameterised code through power cuts, because "works on my machine" is an excuse their situation has never allowed them.
Injection succeeds by smuggling unexpected input into a trusted query. Our Umrah packages follow the opposite discipline: at HTG Travels every tier, hotel name and walking distance goes in writing before you pay a single rupee, so nothing unexpected executes later. Message the desk on WhatsApp at +92 317 5054959 for a visa run done between sprints.




