您的位置:首页 > 数据库

关于Ibatis 的自动防止SQL 注入

2012-11-28 22:49 357 查看
转载于:/article/10387355.html

假设用户执行

[java] view plaincopyprint?

select * from product where id =
5

[c-sharp]
view plaincopyprint?

select * from product where id=5;  delete  from  orders

select * from product where id=5;  delete  from  orders
.

在执行完select后,还将删除orders表里的所有记录。(如果他只删了这些记录,已经谢天谢地了,他可能会做更可怕地事情)。

不过庆幸的是,Ibatis使用的是预编译语句(PreparedStatement

s )。

上述语句会被编译为,

[java] view plaincopyprint?

select * from product where id=?

[java] view plaincopyprint?

SELECT * FROM $TABLE_NAME$ WHERE $COLUMN_NAME$ = #value#

SELECT * FROM $TABLE_NAME$ WHERE $COLUMN_NAME$ = #value#


这时你一定要仔细过滤那些值以避免SQL注入。当然这种情况不只存在Ibatis中。

参考资料:

【iBATIS in Action】 3.5.2 SQL injection
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: