SQL Injection in Different Contexts
What you'll learn: How SQL injection works beyond simple SELECT statements — in INSERT, UPDATE, DELETE operations, and stored procedures.
So far, you've seen SQL injection primarily targeting SELECT queries that fetch data. But attackers don't stop there. Web applications perform many database operations, and each one can be vulnerable if user input isn't properly sanitized.
Beyond SELECT: Different Operations, Same Vulnerability
INSERT statements create new records. Imagine a user registration form:
INSERT INTO users (username, email) VALUES ('$username', '$email');
An attacker might inject: admin', 'admin@evil.com'); DROP TABLE users;-- transforming the query into something destructive.
UPDATE statements modify existing data. Password change forms are common targets:
UPDATE users SET password='$newPass' WHERE username='$user';
Injecting ' OR '1'='1 could change everyone's password, not just one user's.
DELETE statements remove records:
DELETE FROM posts WHERE id=$postId;
Without proper validation, an attacker could inject logic to delete unintended rows or entire tables.
Stored Procedures: Hidden Complexity
Stored procedures are pre-written SQL functions stored in the database. Developers sometimes assume they're immune to injection — they're not. If a stored procedure concatenates user input into dynamic SQL instead of using parameters, injection remains possible.
Think of it like this: Whether you're writing a letter (SELECT), adding a name to a list (INSERT), crossing out entries (DELETE), or updating an address book (UPDATE), if someone can slip malicious instructions into any of those actions, they can cause chaos. The operation type doesn't matter — unsanitized input is always the vulnerability.
Detection Strategy
Test every form field and parameter that interacts with the database, regardless of what the application appears to do with it. Registration forms, profile updates, deletion confirmations — all are potential injection points.
Key Takeaway: SQL injection isn't limited to SELECT queries; INSERT, UPDATE, DELETE statements and stored procedures are equally vulnerable when they incorporate unsanitized user input into SQL operations.