Can I protect against SQL injection by escaping single-quote and surrounding user input with single-quotes?

后端 未结 18 2418
忘了有多久
忘了有多久 2020-11-22 14:03

I realize that parameterized SQL queries is the optimal way to sanitize user input when building queries that contain user input, but I\'m wondering what is wrong with takin

18条回答
  •  攒了一身酷
    2020-11-22 14:46

    Simple answer: It will work sometimes, but not all the time. You want to use white-list validation on everything you do, but I realize that's not always possible, so you're forced to go with the best guess blacklist. Likewise, you want to use parametrized stored procs in everything, but once again, that's not always possible, so you're forced to use sp_execute with parameters.

    There are ways around any usable blacklist you can come up with (and some whitelists too).

    A decent writeup is here: http://www.owasp.org/index.php/Top_10_2007-A2

    If you need to do this as a quick fix to give you time to get a real one in place, do it. But don't think you're safe.

提交回复
热议问题