Skip to content

Commit c27c180

Browse files
committed
Server:@having防 _key 绕过安全检查!例如 strcmp(_password,'123456')=0
1 parent 9ff6891 commit c27c180

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

APIJSON-Java-Server/APIJSONLibrary/src/main/java/zuo/biao/apijson/server/AbstractSQLConfig.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,23 +327,27 @@ public String getHavingString() {
327327
method = expression.substring(0, start);
328328

329329
if (StringUtil.isName(method) == false) {
330-
throw new IllegalArgumentException("字符 " + method + " 不合法!@having:\"function0(...)condition0;function1(...)condition1...\""
330+
throw new IllegalArgumentException("字符 " + method + " 不合法!"
331+
+ "预编译模式下 @having:\"function0(arg0,arg1,...)operator value;function1(arg0,arg1,...)operator value\""
331332
+ " 中SQL函数名 function 必须符合正则表达式 ^[0-9a-zA-Z_]+$ !");
332333
}
333334

334335
suffix = expression.substring(end + 1, expression.length());
335336

336337
if (isPrepared() && PATTERN_RANGE.matcher((String) suffix).matches() == false) {
337-
throw new UnsupportedOperationException("字符串 " + suffix + " 不合法!预编译模式下 @having:\"function0(...)condition0;function1(...)condition1...\""
338+
throw new UnsupportedOperationException("字符串 " + suffix + " 不合法!"
339+
+ "预编译模式下 @having:\"function0(arg0,arg1,...)operator value;function1(arg0,arg1,...)operator value\""
338340
+ " 中 condition 必须符合正则表达式 ^[0-9%!=<>,]+$ !不允许空格!");
339341
}
340342

341343
String[] ckeys = StringUtil.split(expression.substring(start + 1, end));
342344

343345
for (int j = 0; j < ckeys.length; j++) {
344346

345-
if (isPrepared() && StringUtil.isName(ckeys[j]) == false) {
346-
throw new IllegalArgumentException("@having:'function0(arg0,arg1,...);function1(arg0,arg1,...)' 中所有 arg 都必须是1个单词!并且不要有空格!");
347+
if (isPrepared() && (StringUtil.isName(ckeys[j]) == false || ckeys[j].startsWith("_"))) {
348+
throw new IllegalArgumentException("字符 " + ckeys[j] + " 不合法!"
349+
+ "预编译模式下 @having:\"function0(arg0,arg1,...)operator value;function1(arg0,arg1,...)operator value\""
350+
+ " 中所有 arg 都必须是1个不以 _ 开头的单词!并且不要有空格!");
347351
}
348352

349353
ckeys[j] = getKey(ckeys[j]);

0 commit comments

Comments
 (0)