SQL injection

An attack that inserts SQL syntax into input an application builds into a database query, letting the attacker read, change or delete data; parameterised queries are the primary defence.

SQL injection occurs when an application builds a database query by joining untrusted input directly into the SQL text. Input such as ' OR '1'='1 can alter the logic of a query so that it returns every row, and other payloads can read other tables, modify or delete records, or bypass a login check. In blind SQL injection the application shows no query results or errors, so the attacker infers answers from page behaviour or response delays. The weakness is catalogued as CWE-89 and sits within the Injection category of the 2025 OWASP Top 10.

The root cause is data being treated as code. The primary defence is the parameterised query, or prepared statement, which sends the query structure and the data separately so input cannot change the query’s meaning; stored procedures written the same way give similar protection. Input validation, least-privilege database accounts and a web application firewall add depth but do not replace parameterisation. SAST and DAST can both detect it.

Exam relevance: a scenario showing quote marks or SQL keywords in a form field or URL is likely to describe SQL injection. Candidates are expected to prefer parameterised queries over filtering or a WAF alone, and to keep it apart from cross-site scripting, which targets the user’s browser rather than the database.