Skip to content

Commit e609c86

Browse files
committed
解决关闭权限校验时 POST 请求传 userId 无效,加强对 POST 请求内字段格式的校验
1 parent d803766 commit e609c86

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

APIJSONORM/src/main/java/apijson/orm/AbstractSQLConfig.java

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4568,10 +4568,20 @@ else if (userId instanceof Subquery) {}
45684568
Set<String> set = request.keySet(); //前面已经判断request是否为空
45694569
if (method == POST) { //POST操作
45704570
if (idIn != null) {
4571-
throw new IllegalArgumentException(table + ":{} 里的 " + idInKey + ": value 不合法!POST 请求中不允许传 " + idInKey + " !");
4572-
}
4571+
throw new IllegalArgumentException(table + ":{" + idInKey + ": value} 里的 key 不合法!POST 请求中不允许传 " + idInKey
4572+
+ " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!"); }
4573+
if (userIdIn != null) {
4574+
throw new IllegalArgumentException(table + ":{" + userIdInKey + ": value} 里的 key 不合法!POST 请求中不允许传 " + userIdInKey
4575+
+ " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!"); }
45734576

45744577
if (set != null && set.isEmpty() == false) { //不能直接return,要走完下面的流程
4578+
for (String k : set) {
4579+
if (StringUtil.isName(k) == false) {
4580+
throw new IllegalArgumentException(table + ":{" + k + ": value} 里的 key 不合法!POST 请求中不允许传 " + k
4581+
+ " 这种非字段命名 key !必须为 英文字母 开头且只包含 英文字母、数字、下划线的 字段命名!");
4582+
}
4583+
}
4584+
45754585
String[] columns = set.toArray(new String[]{});
45764586

45774587
Collection<Object> valueCollection = request.values();
@@ -4581,24 +4591,25 @@ else if (userId instanceof Subquery) {}
45814591
throw new Exception("服务器内部错误:\n" + TAG
45824592
+ " newSQLConfig values == null || values.length != columns.length !");
45834593
}
4584-
column = (id == null ? "" : idKey + ",") + StringUtil.getString(columns); //set已经判断过不为空
4594+
4595+
column = (id == null ? "" : idKey + ",") + (userId == null ? "" : userIdKey + ",") + StringUtil.getString(columns); //set已经判断过不为空
45854596

4586-
List<List<Object>> valuess = new ArrayList<>(1);
4587-
List<Object> items; //(item0, item1, ...)
4588-
if (id == null) { //数据库自增 id
4589-
items = Arrays.asList(values); //FIXME 是否还需要进行 add 或 remove 操作?Arrays.ArrayList 不允许修改,会抛异常
4590-
}
4591-
else {
4592-
int size = columns.length + (id == null ? 0 : 1); //以key数量为准
4597+
int idCount = id == null ? (userId == null ? 0 : 1) : (userId == null ? 1 : 2);
4598+
int size = idCount + columns.length; // 以 key 数量为准
45934599

4594-
items = new ArrayList<>(size);
4595-
items.add(id); //idList.get(i)); //第0个就是id
4600+
List<Object> items = new ArrayList<>(size); // VALUES(item0, item1, ...)
4601+
if (id != null) {
4602+
items.add(id); // idList.get(i)); // 第 0 个就是 id
4603+
}
4604+
if (userId != null) {
4605+
items.add(userId); // idList.get(i)); // 第 1 个就是 userId
4606+
}
45964607

4597-
for (int j = 1; j < size; j++) {
4598-
items.add(values[j-1]); //从第1个开始,允许"null"
4599-
}
4608+
for (int j = 0; j < values.length; j++) {
4609+
items.add(values[j]); // 从第 1 个开始,允许 "null"
46004610
}
46014611

4612+
List<List<Object>> valuess = new ArrayList<>(1);
46024613
valuess.add(items);
46034614
config.setValues(valuess);
46044615
}

0 commit comments

Comments
 (0)