Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
624d9213
提交
624d9213
authored
2月 25, 2021
作者:
fit2cloud-chenyw
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 禁用alibaba-fastjson 重大安全漏洞
上级
38df90d3
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
2 行增加
和
135 行删除
+2
-135
JSONSchemaGenerator.java
...in/java/io/dataease/commons/json/JSONSchemaGenerator.java
+0
-0
JsonPathUtils.java
...rc/main/java/io/dataease/commons/utils/JsonPathUtils.java
+0
-133
ResultResponseBodyAdvice.java
...dataease/controller/handler/ResultResponseBodyAdvice.java
+2
-2
没有找到文件。
backend/src/main/java/io/dataease/commons/json/JSONSchemaGenerator.java
deleted
100644 → 0
浏览文件 @
38df90d3
差异被折叠。
点击展开。
backend/src/main/java/io/dataease/commons/utils/JsonPathUtils.java
deleted
100644 → 0
浏览文件 @
38df90d3
package
io
.
dataease
.
commons
.
utils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONPath
;
import
org.apache.commons.lang3.StringUtils
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
public
class
JsonPathUtils
{
public
static
List
<
HashMap
>
getListJson
(
String
jsonString
)
{
JSON
jsonObject
=
jsonString
.
startsWith
(
"["
)?
JSONObject
.
parseArray
(
jsonString
):
JSONObject
.
parseObject
(
jsonString
);
List
<
HashMap
>
allJsons
=
new
ArrayList
<>();
// 获取到所有jsonpath后,获取所有的key
List
<
String
>
jsonPaths
=
new
ArrayList
<>(
JSONPath
.
paths
(
jsonObject
).
keySet
());
//去掉根节点key
List
<
String
>
parentNode
=
new
ArrayList
<>();
//根节点key
parentNode
.
add
(
"/"
);
//循环获取父节点key,只保留叶子节点
for
(
int
i
=
0
;
i
<
jsonPaths
.
size
();
i
++)
{
if
(
jsonPaths
.
get
(
i
).
lastIndexOf
(
"/"
)
>
0
)
{
parentNode
.
add
(
jsonPaths
.
get
(
i
).
substring
(
0
,
jsonPaths
.
get
(
i
).
lastIndexOf
(
"/"
)));
}
}
//remove父节点key
for
(
String
parentNodeJsonPath
:
parentNode
)
{
jsonPaths
.
remove
(
parentNodeJsonPath
);
}
Iterator
<
String
>
jsonPath
=
jsonPaths
.
iterator
();
//将/替换为点.
while
(
jsonPath
.
hasNext
())
{
Map
<
String
,
String
>
item
=
new
HashMap
<>();
String
o_json_path
=
"$"
+
jsonPath
.
next
().
replaceAll
(
"/"
,
"."
);
String
value
=
JSONPath
.
eval
(
jsonObject
,
o_json_path
).
toString
();
if
(
value
.
equals
(
""
)
||
value
.
equals
(
"[]"
)
||
o_json_path
.
equals
(
""
))
{
continue
;
}
String
json_path
=
formatJson
(
o_json_path
);
item
.
put
(
"json_path"
,
json_path
);
item
.
put
(
"json_value"
,
addEscapeForString
(
value
));
allJsons
.
add
((
HashMap
)
item
);
}
Collections
.
sort
(
allJsons
,
(
a
,
b
)
->
(
(
String
)
a
.
get
(
"json_path"
)
)
.
compareTo
(
(
String
)
b
.
get
(
"json_path"
)
)
);
// 正则特殊字符转义
allJsons
.
forEach
(
item
->
{
item
.
put
(
"regular_expression"
,
escapeExprSpecialWord
((
String
)
item
.
get
(
"json_value"
)));
});
return
allJsons
;
}
public
static
String
escapeExprSpecialWord
(
String
keyword
)
{
if
(
StringUtils
.
isNotBlank
(
keyword
))
{
String
[]
fbsArr
=
{
"\\"
,
"$"
,
"("
,
")"
,
"*"
,
"+"
,
"."
,
"["
,
"]"
,
"?"
,
"^"
,
"{"
,
"}"
,
"|"
};
for
(
String
key
:
fbsArr
)
{
if
(
keyword
.
contains
(
key
))
{
keyword
=
keyword
.
replace
(
key
,
"\\"
+
key
);
}
}
}
return
keyword
;
}
private
static
String
formatJson
(
String
json_path
){
String
ret
=
""
;
String
reg
=
".(\\d{1,3}).{0,1}"
;
Boolean
change_flag
=
false
;
Matcher
m1
=
Pattern
.
compile
(
reg
).
matcher
(
json_path
);
String
newStr
=
""
;
int
rest
=
0
;
String
tail
=
""
;
while
(
m1
.
find
())
{
int
start
=
m1
.
start
();
int
end
=
m1
.
end
()
-
1
;
if
(
json_path
.
charAt
(
start
)
!=
'.'
||
json_path
.
charAt
(
end
)
!=
'.'
)
{
continue
;
}
newStr
+=
json_path
.
substring
(
rest
,
m1
.
start
())
+
"["
+
json_path
.
substring
(
start
+
1
,
end
)
+
"]."
;
rest
=
m1
.
end
();
tail
=
json_path
.
substring
(
m1
.
end
());
change_flag
=
true
;
}
if
(
change_flag
)
{
ret
=
newStr
+
tail
;
}
else
{
ret
=
json_path
;
}
return
ret
;
}
private
static
String
addEscapeForString
(
String
input
)
{
String
ret
=
""
;
String
reg
=
"[?*/]"
;
Boolean
change_flag
=
false
;
Matcher
m1
=
Pattern
.
compile
(
reg
).
matcher
(
input
);
String
newStr
=
""
;
int
rest
=
0
;
String
tail
=
""
;
while
(
m1
.
find
())
{
newStr
+=
input
.
substring
(
rest
,
m1
.
start
())
+
"\\"
+
m1
.
group
(
0
)
;
rest
=
m1
.
end
();
tail
=
input
.
substring
(
m1
.
end
());
change_flag
=
true
;
}
if
(
change_flag
)
{
ret
=
newStr
+
tail
;
}
else
{
ret
=
input
;
}
return
ret
;
}
}
backend/src/main/java/io/dataease/controller/handler/ResultResponseBodyAdvice.java
浏览文件 @
624d9213
package
io
.
dataease
.
controller
.
handler
;
package
io
.
dataease
.
controller
.
handler
;
import
com.
alibaba.fastjson.JSON
;
import
com.
google.gson.Gson
;
import
io.dataease.controller.ResultHolder
;
import
io.dataease.controller.ResultHolder
;
import
io.dataease.controller.handler.annotation.NoResultHolder
;
import
io.dataease.controller.handler.annotation.NoResultHolder
;
import
org.springframework.core.MethodParameter
;
import
org.springframework.core.MethodParameter
;
...
@@ -37,7 +37,7 @@ public class ResultResponseBodyAdvice implements ResponseBodyAdvice<Object> {
...
@@ -37,7 +37,7 @@ public class ResultResponseBodyAdvice implements ResponseBodyAdvice<Object> {
if
(!(
o
instanceof
ResultHolder
))
{
if
(!(
o
instanceof
ResultHolder
))
{
if
(
o
instanceof
String
)
{
if
(
o
instanceof
String
)
{
return
JSON
.
toJSONString
(
ResultHolder
.
success
(
o
));
return
new
Gson
().
toJson
(
ResultHolder
.
success
(
o
));
}
}
return
ResultHolder
.
success
(
o
);
return
ResultHolder
.
success
(
o
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论