Skip to main content
Module 2 · Lesson 1 of 44/42 in the course~16 min
Module lessons (1/4)

Auth Bypass via SQL Injection

Lesson preview6 hands-on exercises readyApplication & Web Security · Module 2 — Injection & Database Security (PostgreSQL)

Break an unsafe string-concatenated login function, then patch it cleanly with EXECUTE ... USING parameters.

What you'll learn in this lesson

  • Explain why concatenating user strings into SQL queries allows quotes (') and comments (--) to rewrite the query's syntax tree.
  • Inspect legitimate sec_users rows, then exploit login_unsafe(...) inside Postgres WASM (PGlite).
  • Remediate dynamic PL/pgSQL queries cleanly with bound parameters ($1, $2) via EXECUTE ... USING, then harden authentication with tenant scoping.

Overview

When backend code builds SQL queries via string concatenation, untrusted user input crosses from a data slot directly into the SQL parser grammar. One unmatched quote (') exits the string literal context and lets attackers append boolean conditions (OR id = 1) and line comments (--) that discard the password check.

Compare how PostgreSQL parses the concatenated query against a prepared parameterized query:

Sections covered in this lesson

  1. 11. String Concatenation vs AST Separation
  2. 22. Interactive SQL Parser & AST Lab
  3. 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
  4. 44. Checkpoints & Code Review
Pro Lesson · Module 2 — Injection & Database Security (PostgreSQL)

Unlock "Auth Bypass via SQL Injection" and the full Application & Web Security curriculum

Break an unsafe string-concatenated login function, then patch it cleanly with EXECUTE ... USING parameters.

Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Application & Web Security plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.