sql注入

1.对于IBatis防止依赖注入的方法

注入条件:a'or 1=1 or '1' like '1

分析说明:修改比较简单,但点比较多

一、修改DAO.xml:

1.7 Code\pcmp\pcmp\com\huawei\sdp\pcmp\contentAssociated\commentmanager

  <isNotEmpty prepend="and" property="userID">
   userid like '%$userID$%' escape '\'
  </isNotEmpty>

修改为:
  <isNotEmpty prepend="and" property="userID">
   userid like '%' || #userID# || '%' escape '\'
  </isNotEmpty>

二、修改JAVA代码,不再需要调用sqlEscape方法,节省开销
com.huawei.sdp.pcmp.contentAssociated.commentmanager.CommentManageDaoImpl

    public PaginationSupport<CommentManageInfo> queryComment(CommentQueryCondition condition,
        PaginationSupport<CommentManageInfo> ps)

        criteria.put("userID", condition.getUserID());

//这里没对userID做Escape,所以有SQL注入的问题,下面的contenName做了Escape所以没有注入的问题,但此方法开销很大

        criteria.put("contentType", condition.getContentType());
        criteria.put("contentName", sqlEscape(condition.getContentName()));
        criteria.put("contentStatus", condition.getCommentStatus());
        criteria.put("startTime", condition.getStartTime());
        criteria.put("endTime", condition.getEndTime());

你可能感兴趣的:(DAO,sql,xml,ibatis)