News for hackers. Stuff that matters.

Ask HN: What do you do to avoid SQL injection attacks?

I've been looking at SQL injection recently and was interested to know what other developers do to prevent these attacks.

Does anyone have anything to add? 1. Use dynamic SQL if and only if there is no other alternative

2. Escape user input always

3. Always assume magic quotes is off

4. Install security updates and patches regularly

5. Remove all the dead SQL's or other codes that you don't use

6. Never display the system defined error message for SQL errors

7. Store database credentials in a separate file

8. Use the principle of least privilege

9. Disable shells

10. Use SQL injection Hack tools to check vulnerabilities

( 6 comments | 6 points | on HN )
Re:Ask HN: What do you do to avoid SQL injection attacks? by benologist on Thursday April 05, 2012 @08:29PM (#3805385)
Parameterized queries - gist of it is it stops you concatenating a bunch of your and their strings together to form your SQL statement.
Re:Ask HN: What do you do to avoid SQL injection attacks? by joubee on Thursday April 05, 2012 @08:34PM (#3805400)
codinghorror.com: Give me parameterized SQL, or give me death

http://www.codinghorror.com/blog/2005/04/give-me-parameteriz...

I have fairly strong feelings when it comes to the stored procedures versus dynamic SQL argument, but one thing is clear: you should never, ever use concatenated SQL strings in your applications. Give me parameterized SQL, or give me death. There are two good reasons you should never do this.

[I need to spend some time looking at this - tyvm benologist]

Re:Ask HN: What do you do to avoid SQL injection attacks? by jordhy on Friday April 06, 2012 @03:29AM (#3806305)
Precisely. I use obfuscated store procedures.
Re:Ask HN: What do you do to avoid SQL injection attacks? by village88 on Monday April 09, 2012 @03:19PM (#3818711)
Agree with all the statements above. We use Active Record for CodeIgniter or ORM Datamapper and stay away from writing manual queries.
Re:Ask HN: What do you do to avoid SQL injection attacks? by ZephyrP on Thursday April 12, 2012 @01:12PM (#3833283)
I wrote my own database.

http://zv.github.com/artifact/

Re:Ask HN: What do you do to avoid SQL injection attacks? by AznHisoka on Friday April 06, 2012 @09:47AM (#3807082)
I used Ruby activerecord and don't write manual queries.