前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java防止sql注入

java防止sql注入

原创
作者头像
用户7705674
修改2021-09-24 14:23:45
2.1K0
修改2021-09-24 14:23:45
举报
文章被收录于专栏:css小迷妹css小迷妹
代码语言:javascript
复制
public final static String filterSQLInjection(String s) {
    if (s == null || "".equals(s)) {
        return "";
    }
    try {
        s = s.trim().replaceAll("</?[s,S][c,C][r,R][i,I][p,P][t,T]>?", "");//script
        s = s.trim().replaceAll("[a,A][l,L][e,E][r,R][t,T]\\(", "").replace("\"", "");// alert
        s = s.trim().replace("\\.swf", "").replaceAll("\\.htc", "");
        s = s.trim().replace("\\.php\\b", "").replaceAll("\\.asp\\b", "");
        s = s.trim().replace("document\\.", "").replaceAll("[e,E][v,V][a,A][l,L]\\(", "");
        s = s.trim().replaceAll("'", "").replaceAll(">", "");
        s = s.trim().replaceAll("<", "").replaceAll("=", "");
        s = s.trim().replaceAll(" [o,O][r,R]", "");
        s = s.trim().replaceAll("etc/", "").replaceAll("cat ", "");
        s = s.trim().replaceAll("/passwd ", "");
        s = s.trim().replaceAll("sleep\\(", "").replaceAll("limit ", "").replaceAll("LIMIT ", "");
        s = s.trim().replaceAll("[d,D][e,E][l,L][e,E][t,T][e,E] ", "");// delete
        s = s.trim().replaceAll("[s,S][e,E][l,L][e,E][c,C][t,T] ", "");// select;
        s = s.trim().replaceAll("[u,U][p,P][d,D][a,A][t,T][e,E] ", "");// update
        s = s.trim().replaceAll("[d,D][e,E][l,L][a,A][y,Y] ", "").replaceAll("waitfor ", "");
        s = s.trim().replaceAll("print\\(", "").replaceAll("md5\\(", "");
        s = s.trim().replaceAll("cookie\\(", "").replaceAll("send\\(", "");
        s = s.trim().replaceAll("response\\.", "").replaceAll("write\\(", "")
                .replaceAll("&", "");
    } catch (Exception e) {
        e.printStackTrace();
        return "";
    }
    return s;
} 

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档