| |||||||||
SQL Injection is a security vulnerability that occurs in the database layer of an application. Its source is the incorrect escaping of variables embedded in SQL statements.
Assuming the following code is embedded in the application, and a parameter "userName" that contains the user's name is given, SQL Injection is possible:
If supplied with "a'; DROP TABLE users; SELECT * FROM data WHERE name LIKE '%" as "userName", the following SQL statement would be generated:
The database would execute the statement in order, selecting data, dropping (deleting) the "users" table and selecting data that maybe was not meant to be displayed to web users. In essence, any data in the database available to the user connecting to the database could be read and/or modified.
SQL Injection is easy to work around with in most programming languages that target web applications or offer functionality. In the Java programming language, the PreparedStatement class should be used.
Instead of
use the following