MCPcopy Create free account
hub / github.com/LisenCoding/cangku / sqlInject

Method sqlInject

boot/src/main/java/com/utils/SQLFilter.java:17–41  ·  view source on GitHub ↗

SQL注入过滤 @param str 待验证的字符串

(String str)

Source from the content-addressed store, hash-verified

15 * @param str 待验证的字符串
16 */
17 public static String sqlInject(String str){
18 if(StringUtils.isBlank(str)){
19 return null;
20 }
21 //去掉'|"|;|\字符
22 str = StringUtils.replace(str, "'", "");
23 str = StringUtils.replace(str, "\"", "");
24 str = StringUtils.replace(str, ";", "");
25 str = StringUtils.replace(str, "\\", "");
26
27 //转换成小写
28 str = str.toLowerCase();
29
30 //非法字符
31 String[] keywords = {"master", "truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"};
32
33 //判断是否包含非法字符
34 for(String keyword : keywords){
35 if(str.indexOf(keyword) != -1){
36 throw new EIException("包含非法字符");
37 }
38 }
39
40 return str;
41 }
42}

Callers 1

QueryMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected