SQL injection

From WikiTech, the free technology encyclopedia

Attack that slips malicious SQL into a database query

3 sources from OWASP Foundation, MITRE and eSecurity Planet. Checked by ByteExplained editors on 5 December 2026. How we check facts

SQL injection is an attack in which an SQL query is inserted, or "injected", through the input data a client sends to an application.[1] It happens when a program builds a database command from outside input without properly removing or quoting SQL syntax, so the input can change the meaning of the command.[2]

Contents
  1. History
  2. How it works
  3. Prevention
  4. See also
  5. References

History

The first public discussion of the technique is credited to the security researcher Jeff Forristal, who wrote under the name Rain Forest Puppy, in 1998 while researching a Windows NT server.[3] The weakness is catalogued by MITRE as CWE-89 and has appeared in every edition of the CWE Top 25 most dangerous software weaknesses list from 2019 to 2025.[2]

How it works

Many applications combine user input with a fixed SQL command to look up records in a Relational database. If the input is pasted straight into the command, an attacker can type text that ends the intended value and adds conditions of their own. In an example given by OWASP, entering name' OR 'a'='a as an item name makes the query's condition always true, so it returns every row in the table, including other users' data.[1]

A successful attack can read sensitive data, insert, update or delete records, carry out administrative operations on the database, retrieve files from the database server and, in some cases, issue commands to the operating system.[1] OWASP notes that it has been especially common in PHP and ASP applications because of older programming interfaces.[1]

Prevention

The main defence is to use prepared statements or parameterised queries, which keep the SQL command separate from the data supplied by users.[1][2] Manually escaping special characters can help but does not make an application secure.[1] Other recommended measures include running database accounts with the fewest privileges needed, validating input, and limiting the detail shown in error messages.[2]

See also

References

  1. ^ SQL Injection. OWASP Foundation. community.owasp.org
  2. ^ CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'). MITRE. cwe.mitre.org
  3. ^ How Was SQL Injection Discovered?. eSecurity Planet. 2013-11-25. esecurityplanet.com
Technologies on WikiTech
Online security
All technologies