categories.security Basic

SQL Injection Attack and Prevention

AI Practice

Explain SQL injection attacks and how to prevent them.

How It Works

An attacker injects malicious SQL fragments into input fields, altering the original query logic to bypass authentication, read, or destroy data.

Example: WHERE username='admin'--' bypasses password checking.

Prevention

1. Parameterized Queries

Pass user input as parameters rather than concatenating into SQL strings. The database driver handles escaping automatically.

2. ORM Frameworks

ORMs like Prisma and Sequelize use parameterized queries by default.

3. Input Validation and Whitelisting

Validate data type, length, and format at the API layer.

4. Principle of Least Privilege

Grant database accounts only the minimum necessary permissions to limit attack impact.

✦ AI Mock Interview

Type your answer and get instant AI feedback

Sign in to use AI scoring

Copyright © 2026 Wood All Rights Reserved · FE Interview Hub