SQL injection

An attack where untrusted input is joined into a database query so that part of it runs as SQL, letting an attacker read or change data.

It can expose or destroy the whole database.

In more detail

It happens when code builds a query by joining strings, such as a name that closes the quote and adds its own SQL. The fix is parameterised queries, which send values separately from the SQL text, never escaping by hand. Client choices such as sort keys should map to fixed server expressions rather than raw text.

Examples

Web logs show it as quotes, OR 1=1, comments or UNION SELECT in request parameters, often URL-encoded, so decode before matching.
"SELECT body FROM doc WHERE owner = '" + owner + "'"  with owner = "bob' OR '1'='1"
In the course, the name alice' OR '1'='1 closes the quotation early and returns every row.

Related terms

Taught in

References

Certification courses