修改过滤关键词实现
This commit is contained in:
@@ -6,8 +6,14 @@
|
|||||||
package com.jero.config.filter.xss;
|
package com.jero.config.filter.xss;
|
||||||
|
|
||||||
import com.jero.common.exception.JeroBootException;
|
import com.jero.common.exception.JeroBootException;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
public class SqlFilter {
|
public class SqlFilter {
|
||||||
private SqlFilter(){
|
private SqlFilter(){
|
||||||
|
|
||||||
@@ -19,19 +25,22 @@ public class SqlFilter {
|
|||||||
} else {
|
} else {
|
||||||
str = StringUtils.replace(str, "\\n", "Line_Break");
|
str = StringUtils.replace(str, "\\n", "Line_Break");
|
||||||
String[] keywords = new String[]{"truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"};
|
String[] keywords = new String[]{"truncate", "insert", "select", "delete", "update", "declare", "alter", "drop"};
|
||||||
String[] var2 = keywords;
|
|
||||||
int var3 = keywords.length;
|
|
||||||
|
|
||||||
for(int var4 = 0; var4 < var3; ++var4) {
|
List<String> list = Arrays.asList(keywords);
|
||||||
String keyword = var2[var4];
|
String finalStr = str;
|
||||||
int index = StringUtils.indexOfIgnoreCase(str, keyword + " ");
|
List<String> listErr = new CopyOnWriteArrayList<>();
|
||||||
|
list.parallelStream().forEach(p->{
|
||||||
|
int index = StringUtils.indexOfIgnoreCase(finalStr, p + " ");
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
// 判断是否是条款内容
|
// 判断是否是条款内容
|
||||||
if (str.contains("itemContent") || str.contains("item_content")){
|
if (finalStr.contains("itemContent") || finalStr.contains("item_content")){
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
throw new JeroBootException("包含非法字符");
|
listErr.add("1");
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
if(!CollectionUtils.isEmpty(listErr)){
|
||||||
|
throw new JeroBootException("包含非法字符");
|
||||||
}
|
}
|
||||||
str = StringUtils.replace(str, "Line_Break", "\\n");
|
str = StringUtils.replace(str, "Line_Break", "\\n");
|
||||||
return str;
|
return str;
|
||||||
|
|||||||
Reference in New Issue
Block a user