In short
An SQL injection occurs when user-supplied data is inserted verbatim into a database query, allowing an attacker to manipulate that query: to read the entire database, bypass authentication, or even modify or delete data. A reliable defense has been known for a long time: parameterized queries. Yet it remains on the OWASP Top 10, under the Injection category.
An example
An application constructs its query by pasting the entered text: SELECT * FROM clients WHERE email = '[input]'. If the attacker enters ' OR '1'='1, the condition always evaluates to true, and the query returns all clients. Variations of this attack allow an attacker to read other tables, even when the application does not display anything (“blind” injection, based on response time).
How to Protect Against It
- Prepared statements or ORM used correctly: the data is never interpreted as code.
- Never concatenate user input into SQL, including for column names or sort order (use a whitelist).
- Database account with minimal privileges.
- Generic error messages that provide no details about the query.
Frequently asked questions
Do ORMs protect against SQL injection?
Yes, as long as you use their parameterized methods. Functions that accept raw SQL remain vulnerable if data is concatenated into them.
Sources
Find out where an attacker would get in.
Our AI agents actually attack your scope, fully automated, and hand you the proof of every vulnerability.
