Preventing SQL Injection in Raw Queries and Modern ORMs
Why string concatenation in raw queries and unsafe ORM raw clauses ($queryRawUnsafe) lead to database compromise, and how to use parameterized queries.
Why AI coding tools introduce this vulnerability
When building complex filters (search, sort, pagination), AI coding tools frequently resort to string interpolation: `SELECT * FROM users WHERE name LIKE '%${searchTerm}%'` or ORM raw escapes like prisma.$queryRawUnsafe(...), exposing the application to classic SQL injection.
Technical Vulnerability Analysis
SQL injection occurs when user-supplied input is directly concatenated into SQL statement text rather than passed as isolated parameters to the database driver. Attackers can execute arbitrary queries, extract entire database tables, alter records, and in some database configurations, execute system commands.
Remediation Playbook & Code Fixes
Why this fix works: Always pass values as positional parameters. The database driver escapes and sanitizes them.
Local CLI Verification Commands
Pre-Deployment Self-Audit Checklist
Knowledge Check: Verify Your Understanding
What is the primary architectural cause of preventing sql injection in raw queries and modern orms?
Test your website for ZX-SQLI-001
Run our 14 deterministic engines to inspect your live deployment.