fix: 增加防sql注入逻辑 (#18564)

This commit is contained in:
王嘉豪
2026-06-11 11:52:44 +08:00
committed by GitHub
parent f6f704813b
commit 4463e21cb7

View File

@@ -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);
}
}