mirror of
https://github.com/dataease/dataease.git
synced 2026-06-12 16:31:11 +08:00
fix: 增加防sql注入逻辑 (#18564)
This commit is contained in:
@@ -155,11 +155,11 @@ public class Quota2SQLObj {
|
||||
} else if (StringUtils.equalsIgnoreCase(f.getTerm(), "not_empty")) {
|
||||
whereValue = "''";
|
||||
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "in")) {
|
||||
whereValue = "('" + StringUtils.join(f.getValue(), "','") + "')";
|
||||
whereValue = "('" + StringUtils.join(sanitizeSqlLiteral(f.getValue()), "','") + "')";
|
||||
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
|
||||
whereValue = "'%" + f.getValue() + "%'";
|
||||
whereValue = "'%" + sanitizeSqlLiteral(f.getValue()) + "%'";
|
||||
} else {
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, f.getValue());
|
||||
whereValue = String.format(SQLConstants.WHERE_VALUE_VALUE, sanitizeSqlLiteral(f.getValue()));
|
||||
}
|
||||
list.add(SQLObj.builder()
|
||||
.whereField(fieldAlias)
|
||||
@@ -173,4 +173,10 @@ public class Quota2SQLObj {
|
||||
return !CollectionUtils.isEmpty(list) ? "(" + String.join(" " + Utils.getLogic(y.getLogic()) + " ", strList) + ")" : null;
|
||||
}
|
||||
|
||||
private static String sanitizeSqlLiteral(String value) {
|
||||
String normalized = StringUtils.defaultString(value);
|
||||
Utils.validateSqlInjectionRisk(normalized);
|
||||
return Utils.transValue(normalized);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user