ibatis解决sql注入问题 .
2012-12-02 13:50
183 查看
最近看看了SQL注入的问题,这篇文章解决了ibatis如何防sql注入攻击,值得参考,转自/article/2589800.html
对于ibaits参数引用可以使用#和$两种写法,其中#写法会采用预编译方式,将转义交给了数据库,不会出现注入问题;如果采用$写法,则相当于拼接字符串,会出现注入问题。
例如,如果属性值为“' or '1'='1 ”,采用#写法没有问题,采用$写法就会有问题。
对于like语句,难免要使用$写法,
1. 对于Oracle可以通过'%'||'#param#'||'%'避免;
2. 对于MySQL可以通过CONCAT('%',#param#,'%')避免;
3. MSSQL中通过'%'+#param#+'% 。
如下3种SQL语句:
[html]
view plaincopyprint?
mysql: select * from t_user where name like concat('%',#name #,'%')
oracle: select * from t_user where name like '%'||#name #||'%'
SQL Server:select * from t_user where name like '%'+#name #+'%
对于ibaits参数引用可以使用#和$两种写法,其中#写法会采用预编译方式,将转义交给了数据库,不会出现注入问题;如果采用$写法,则相当于拼接字符串,会出现注入问题。
例如,如果属性值为“' or '1'='1 ”,采用#写法没有问题,采用$写法就会有问题。
对于like语句,难免要使用$写法,
1. 对于Oracle可以通过'%'||'#param#'||'%'避免;
2. 对于MySQL可以通过CONCAT('%',#param#,'%')避免;
3. MSSQL中通过'%'+#param#+'% 。
如下3种SQL语句:
[html]
view plaincopyprint?
mysql: select * from t_user where name like concat('%',#name #,'%')
oracle: select * from t_user where name like '%'||#name #||'%'
SQL Server:select * from t_user where name like '%'+#name #+'%
mysql: select * from t_user where name like concat('%',#name #,'%') oracle: select * from t_user where name like '%'||#name #||'%' SQL Server:select * from t_user where name like '%'+#name #+'%
相关文章推荐
- (转载)ibatis:解决sql注入问题
- ibatis解决sql注入问题 .
- ibatis解决sql注入问题
- ibatis解决sql注入问题
- iBatis解决sql注入问题的方法
- ibatis解决sql注入问题
- 通过ibatis解决sql注入问题
- ibatis解决sql注入问题
- ibatis解决sql注入问题
- ibatis解决sql注入问题
- PDO(PHP Data Object),Mysqli,以及对sql注入等问题的解决
- 使用Ibatis生成的代码日期中没有时分秒的问题原因和解决办法
- 解决Ibatis一对多映射n+1问题 ----ibatis2.2.0版本
- IBatis.Net 学习中遇到的问题及解决办法
- 学习mybatis框架中遇到org.apache.ibatis.exceptions.PersistenceException: 问题该怎么解决
- iBATIS一对多/多对多N+1问题解决方案
- iBatis解决自动防止sql注入
- ibatis处理sybase分页的问题(还没有解决)
- 数据库之解决SQL注入问题
- iBatis终于出了2.0.9,解决了N+1查询问题。