本文发表在 rolia.net 枫下论坛前几天有个关于存储过程(stored procedure)在web应用中的讨论。有篇文章这样反驳sp的安全性:
http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html
It is also said that stored procedures are more secure because they prevent SQL injection attacks. This argument is false for the simple reason that it is possible to have a stored procedure which concatenates strings together and therefore open itself up to sql injection attacks (generally seen in systems which use procedures and have to offer some sort of general search routine), while the use of parameterized queries removes this vulnerability as no value can end up as being part of the actually query string.
幸亏不是每个DB程序员都这样蠢。这里是一些避免攻击应该掌握的原则,欢迎大家补充!
1.输入的参数只能用作绑定变量;永远不要用输入的东西拼装动态SQL。这样就避免了SQL注入攻击。这个原则哪怕不用存储过程也应该坚持。
2.只给予AS连接DB用户有限的权限。除了执行某些存储过程之外,回收大部分表的读写权限。最多保留某些不重要的表和视图的读权限。这样子注入的SQL也执行不了。
3.对于重要的操作在SP入口处再次验证用户身份更多精彩文章及讨论,请光临枫下论坛 rolia.net
http://www.tonymarston.net/php-mysql/stored-procedures-are-evil.html
It is also said that stored procedures are more secure because they prevent SQL injection attacks. This argument is false for the simple reason that it is possible to have a stored procedure which concatenates strings together and therefore open itself up to sql injection attacks (generally seen in systems which use procedures and have to offer some sort of general search routine), while the use of parameterized queries removes this vulnerability as no value can end up as being part of the actually query string.
幸亏不是每个DB程序员都这样蠢。这里是一些避免攻击应该掌握的原则,欢迎大家补充!
1.输入的参数只能用作绑定变量;永远不要用输入的东西拼装动态SQL。这样就避免了SQL注入攻击。这个原则哪怕不用存储过程也应该坚持。
2.只给予AS连接DB用户有限的权限。除了执行某些存储过程之外,回收大部分表的读写权限。最多保留某些不重要的表和视图的读权限。这样子注入的SQL也执行不了。
3.对于重要的操作在SP入口处再次验证用户身份更多精彩文章及讨论,请光临枫下论坛 rolia.net