Tuesday, July 14, 2009

SQL injection - Programmer's challenge

"SQL injection is a code injection technique that exploits a security vulnerability occurring in the database layer of an application. The vulnerability is present when user input is either incorrectly filtered for string literal escape characters embedded in SQL statements or user input is not strongly typed and thereby unexpectedly executed. It is an instance of a more general class of vulnerabilities that can occur whenever one programming or scripting language is embedded inside another. SQL injection attacks are also known as SQL insertion attacks" - Wikipedia.

Following are some of the good articles that I came across

To sum we can prevent SQL insertion to a greater extent by following the following approaches:
1) Sanitize the input
a) Validate your inputs
b) Get the good content in the input and minimise the bad content

2) Escape/Quote safe the input - Ensure that quotes or escape characters are well handled

3) Use bound parameters or parameterized query statements

4) Use stored procedures for database access

5) Configure error reporting - Errors displayed to the user should not contain database details

6) Limit database permissions and segregate users