What is SQL injection?
An attack that exploits a web application building SQL statements by simply concatenating user input, using the input to change the meaning of the command and manipulate the database without authorization. Prepared statements with placeholders are the fundamental countermeasure.
Japanese name: SQLインジェクション
SQL injection appears in 3 practice questions across 1 topic, including Information Security Basics.
Field: Information Security Basics
How the attack works
If an application builds an SQL statement by concatenating strings such as "… WHERE name = '", the input value and "'", a quotation mark in the input closes the string, and whatever follows is interpreted as SQL commands. With the textbook input ' OR '1'='1, the always-true condition "or '1' equals '1'" is added, letting authentication be bypassed. It can also lead to data being read, altered or deleted.
FAQ
Can SQL injection be prevented by escaping?
Escaping can prevent it in some cases, but every rule for each database type and character encoding must be handled without omission, and a single gap lets the attack succeed. Prepared statements with placeholders are therefore the basic countermeasure.
Can SQL injection be prevented by limiting the length of input?
No. Even short strings can change the meaning of a command. Limits on length or kinds of characters are supplementary measures; the fundamental countermeasure is prepared statements.