Module lessons (1/4)
Auth Bypass via SQL Injection
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_usersrows, then exploitlogin_unsafe(...)inside Postgres WASM (PGlite). - Remediate dynamic PL/pgSQL queries cleanly with bound parameters (
$1,$2) viaEXECUTE ... 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
- 11. String Concatenation vs AST Separation
- 22. Interactive SQL Parser & AST Lab
- 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
- 44. Checkpoints & Code Review
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.