Bitzu

312-50 ยท SQL injection

SQL injection countermeasures

Parameterized queries, stored procedures, input validation, least-privilege database accounts, WAF, error handling, and detection.

Key points

  • Primary fix: parameterized queries (prepared statements) keep code and data separate.
  • Safe stored procedures work too, but dynamic SQL inside them is injectable.
  • Allow-list validation for values that cannot be bound (table, column names).
  • Least-privilege database accounts.
  • Generic user errors, detailed server-side logs.
  • WAF as a compensating layer; monitoring to detect attacks.

Source: https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html

Practice questions

Single choice

Which measure is the preferred primary defence against SQL injection?

  1. Hiding database errors from users
  2. Parameterized queries (prepared statements)
  3. Blocking the apostrophe character in a client-side script
  4. Renaming database tables
Show answer

Answer: B. Parameterized queries (prepared statements)

Parameterized queries ensure input is always treated as data. A WAF or error hiding only reduces exposure.

Select all that apply

Which controls reduce SQL injection risk?

  1. Prepared statements with bound parameters
  2. A least-privilege database account
  3. Allow-list validation of values like sort column names
  4. Showing full database errors to users
  5. Relying only on browser-side validation
Show answer

Answer: A. Prepared statements with bound parameters, B. A least-privilege database account, C. Allow-list validation of values like sort column names

Parameterization, least privilege and allow-list validation all help. Showing full errors leaks information, and trusting client-side checks alone is easily bypassed.

True or false

Any stored procedure is automatically safe from SQL injection.

Show answer

Answer: False

False. A procedure that builds dynamic SQL by concatenating its arguments is still injectable; only safe, parameterized procedures protect.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More 312-50 topics in this module