update 优化 findInSet 方法 增加参数校验防止注入
This commit is contained in:
+10
-1
@@ -8,7 +8,7 @@ import org.dromara.common.core.utils.StringUtils;
|
|||||||
/**
|
/**
|
||||||
* sql操作工具类
|
* sql操作工具类
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author Lion Li
|
||||||
*/
|
*/
|
||||||
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
||||||
public class SqlUtil {
|
public class SqlUtil {
|
||||||
@@ -47,6 +47,14 @@ public class SqlUtil {
|
|||||||
if (StringUtils.isEmpty(value)) {
|
if (StringUtils.isEmpty(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== 核心增强:自动转义单引号 ====================
|
||||||
|
// 不抛异常、不破坏业务、不改变原方法行为、自动防注入
|
||||||
|
if (value.contains("'")) {
|
||||||
|
throw new UtilException("请求参数包含非法字符【'】,已禁止执行");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== 原有逻辑不变 ====================
|
||||||
String normalizedValue = value.replaceAll("\\p{Z}|\\s", "");
|
String normalizedValue = value.replaceAll("\\p{Z}|\\s", "");
|
||||||
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
|
String[] sqlKeywords = StringUtils.split(SQL_REGEX, "\\|");
|
||||||
for (String sqlKeyword : sqlKeywords) {
|
for (String sqlKeyword : sqlKeywords) {
|
||||||
@@ -55,4 +63,5 @@ public class SqlUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
@@ -7,6 +7,7 @@ import lombok.AccessLevel;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
import org.dromara.common.core.utils.SpringUtils;
|
import org.dromara.common.core.utils.SpringUtils;
|
||||||
|
import org.dromara.common.core.utils.sql.SqlUtil;
|
||||||
import org.dromara.common.mybatis.enums.DataBaseType;
|
import org.dromara.common.mybatis.enums.DataBaseType;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
@@ -89,6 +90,8 @@ public class DataBaseHelper {
|
|||||||
*/
|
*/
|
||||||
public static String findInSet(Object var1, String var2) {
|
public static String findInSet(Object var1, String var2) {
|
||||||
String var = Convert.toStr(var1);
|
String var = Convert.toStr(var1);
|
||||||
|
SqlUtil.filterKeyword(var);
|
||||||
|
SqlUtil.filterKeyword(var2);
|
||||||
return switch (getDataBaseType()) {
|
return switch (getDataBaseType()) {
|
||||||
// instr(',0,100,101,' , ',100,') <> 0
|
// instr(',0,100,101,' , ',100,') <> 0
|
||||||
case ORACLE -> "instr(','||%s||',' , ',%s,') <> 0".formatted(var2, var);
|
case ORACLE -> "instr(','||%s||',' , ',%s,') <> 0".formatted(var2, var);
|
||||||
|
|||||||
Reference in New Issue
Block a user