What is SQL injection?

An attack in which user input is treated as part of a database query, letting an attacker read, change or delete data they should never reach. It is prevented by parameterised queries, not by filtering characters.

SQL injection happens when an application builds a query by pasting user input into SQL text, so input such as ' OR '1'='1 changes the query's logic. Depending on the database and permissions, attackers can dump tables, bypass logins, modify records or sometimes run commands on the server. The reliable fix is parameterised queries (prepared statements), which keep data and code separate, backed by least-privilege database accounts and input validation. Web application firewalls can block common payloads but are a backstop, not a fix. SQL injection has been understood for decades and still appears regularly in breach reports and the OWASP Top 10.

Source: NIST CSRC Glossary (NISTIR 7682).

Practice it in a lab

Free, hands-on labs that teach SQL injection. 5 more labs also cover it.

Related terms

All glossary terms

Related