Search GimmeJob

Type at least 2 characters. Enter also searches by meaning.
QA interview question
Databases, SQL & BISQL languageMiddleCommonSecurity

How do parameterized queries prevent SQL injection, and what should still be tested?

Answer

Parameterized queries send SQL structure separately from data values, so hostile input is treated as a value rather than executable syntax. They do not automatically make dynamically chosen identifiers, sort clauses, stored procedures, excessive database privileges or unsafe query construction secure. Test every input path including headers and imported files, verify server-side parameter binding and allowlists, use least-privileged database accounts and confirm that errors and logs do not disclose sensitive query or schema details.

Strong answer includes

  • explains the code-versus-data boundary
  • recognizes dynamic identifiers and privilege risks
  • tests indirect inputs, errors and logging

Practical example

Keep user data outside SQL structure
Dialect · PostgreSQLRuntime · static example

$1 is PostgreSQL positional-parameter syntax and requires a database driver to bind the value separately from SQL text.

-- SQL text sent to the database
SELECT id, email, role
FROM users
WHERE email = $1;

-- The driver binds $1 separately, for example:
-- value: attacker@example.com' OR '1'='1

The placeholder is part of the fixed SQL structure while the supplied text is bound as a value, so quote characters inside the input do not become executable SQL. Dynamic identifiers and ORDER BY fragments still require allowlists rather than value binding.

Expected result: Only a row whose email literally equals the supplied value can match.

#sql#database#sql-injection#security

Sources

OWASP Web Security Testing GuideOWASP · Web application security test coveragePostgreSQL documentationPostgreSQL Global Development Group · Relational modelling, SQL, joins, constraints, transactions, concurrency, indexes, query plans and recovery