Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
6b5dd4d2
提交
6b5dd4d2
authored
7月 28, 2021
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化XSS跨站脚本过滤
上级
e6becb93
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
49 行增加
和
34 行删除
+49
-34
application.yml
ruoyi-admin/src/main/resources/application.yml
+1
-1
SysUser.java
...ain/java/com/ruoyi/common/core/domain/entity/SysUser.java
+1
-1
XssFilter.java
...mmon/src/main/java/com/ruoyi/common/filter/XssFilter.java
+5
-28
StringUtils.java
...mon/src/main/java/com/ruoyi/common/utils/StringUtils.java
+40
-0
FilterConfig.java
...rc/main/java/com/ruoyi/framework/config/FilterConfig.java
+2
-4
没有找到文件。
ruoyi-admin/src/main/resources/application.yml
浏览文件 @
6b5dd4d2
...
@@ -115,6 +115,6 @@ xss:
...
@@ -115,6 +115,6 @@ xss:
# 过滤开关
# 过滤开关
enabled
:
true
enabled
:
true
# 排除链接(多个用逗号分隔)
# 排除链接(多个用逗号分隔)
excludes
:
/system/notice
/*
excludes
:
/system/notice
# 匹配链接
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
urlPatterns
:
/system/*,/monitor/*,/tool/*
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysUser.java
浏览文件 @
6b5dd4d2
...
@@ -201,7 +201,7 @@ public class SysUser extends BaseEntity
...
@@ -201,7 +201,7 @@ public class SysUser extends BaseEntity
this
.
avatar
=
avatar
;
this
.
avatar
=
avatar
;
}
}
@JsonIgnore
@JsonIgnore
@JsonProperty
@JsonProperty
public
String
getPassword
()
public
String
getPassword
()
{
{
...
...
ruoyi-common/src/main/java/com/ruoyi/common/filter/XssFilter.java
浏览文件 @
6b5dd4d2
...
@@ -3,8 +3,6 @@ package com.ruoyi.common.filter;
...
@@ -3,8 +3,6 @@ package com.ruoyi.common.filter;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
javax.servlet.Filter
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
import
javax.servlet.FilterConfig
;
...
@@ -27,16 +25,10 @@ public class XssFilter implements Filter
...
@@ -27,16 +25,10 @@ public class XssFilter implements Filter
*/
*/
public
List
<
String
>
excludes
=
new
ArrayList
<>();
public
List
<
String
>
excludes
=
new
ArrayList
<>();
/**
* xss过滤开关
*/
public
boolean
enabled
=
false
;
@Override
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
{
String
tempExcludes
=
filterConfig
.
getInitParameter
(
"excludes"
);
String
tempExcludes
=
filterConfig
.
getInitParameter
(
"excludes"
);
String
tempEnabled
=
filterConfig
.
getInitParameter
(
"enabled"
);
if
(
StringUtils
.
isNotEmpty
(
tempExcludes
))
if
(
StringUtils
.
isNotEmpty
(
tempExcludes
))
{
{
String
[]
url
=
tempExcludes
.
split
(
","
);
String
[]
url
=
tempExcludes
.
split
(
","
);
...
@@ -45,10 +37,6 @@ public class XssFilter implements Filter
...
@@ -45,10 +37,6 @@ public class XssFilter implements Filter
excludes
.
add
(
url
[
i
]);
excludes
.
add
(
url
[
i
]);
}
}
}
}
if
(
StringUtils
.
isNotEmpty
(
tempEnabled
))
{
enabled
=
Boolean
.
valueOf
(
tempEnabled
);
}
}
}
@Override
@Override
...
@@ -68,25 +56,14 @@ public class XssFilter implements Filter
...
@@ -68,25 +56,14 @@ public class XssFilter implements Filter
private
boolean
handleExcludeURL
(
HttpServletRequest
request
,
HttpServletResponse
response
)
private
boolean
handleExcludeURL
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
{
if
(!
enabled
)
{
return
true
;
}
if
(
excludes
==
null
||
excludes
.
isEmpty
())
{
return
false
;
}
String
url
=
request
.
getServletPath
();
String
url
=
request
.
getServletPath
();
for
(
String
pattern
:
excludes
)
String
method
=
request
.
getMethod
();
// GET DELETE 不过滤
if
(
method
==
null
||
method
.
matches
(
"GET"
)
||
method
.
matches
(
"DELETE"
))
{
{
Pattern
p
=
Pattern
.
compile
(
"^"
+
pattern
);
return
true
;
Matcher
m
=
p
.
matcher
(
url
);
if
(
m
.
find
())
{
return
true
;
}
}
}
return
false
;
return
StringUtils
.
matches
(
url
,
excludes
)
;
}
}
@Override
@Override
...
...
ruoyi-common/src/main/java/com/ruoyi/common/utils/StringUtils.java
浏览文件 @
6b5dd4d2
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
...
@@ -6,6 +6,7 @@ import java.util.HashSet;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Set
;
import
java.util.Set
;
import
org.springframework.util.AntPathMatcher
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.constant.Constants
;
import
com.ruoyi.common.core.text.StrFormatter
;
import
com.ruoyi.common.core.text.StrFormatter
;
...
@@ -463,6 +464,45 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
...
@@ -463,6 +464,45 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
return
sb
.
toString
();
return
sb
.
toString
();
}
}
/**
* 查找指定字符串是否匹配指定字符串列表中的任意一个字符串
*
* @param str 指定字符串
* @param strs 需要检查的字符串数组
* @return 是否匹配
*/
public
static
boolean
matches
(
String
str
,
List
<
String
>
strs
)
{
if
(
isEmpty
(
str
)
||
isEmpty
(
strs
))
{
return
false
;
}
for
(
String
pattern
:
strs
)
{
if
(
isMatch
(
pattern
,
str
))
{
return
true
;
}
}
return
false
;
}
/**
* 判断url是否与规则配置:
* ? 表示单个字符;
* * 表示一层路径内的任意字符串,不可跨层级;
* ** 表示任意层路径;
*
* @param pattern 匹配规则
* @param url 需要匹配的url
* @return
*/
public
static
boolean
isMatch
(
String
pattern
,
String
url
)
{
AntPathMatcher
matcher
=
new
AntPathMatcher
();
return
matcher
.
match
(
pattern
,
url
);
}
@SuppressWarnings
(
"unchecked"
)
@SuppressWarnings
(
"unchecked"
)
public
static
<
T
>
T
cast
(
Object
obj
)
public
static
<
T
>
T
cast
(
Object
obj
)
{
{
...
...
ruoyi-framework/src/main/java/com/ruoyi/framework/config/FilterConfig.java
浏览文件 @
6b5dd4d2
...
@@ -4,6 +4,7 @@ import java.util.HashMap;
...
@@ -4,6 +4,7 @@ import java.util.HashMap;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.DispatcherType
;
import
javax.servlet.DispatcherType
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
...
@@ -17,11 +18,9 @@ import com.ruoyi.common.utils.StringUtils;
...
@@ -17,11 +18,9 @@ import com.ruoyi.common.utils.StringUtils;
* @author ruoyi
* @author ruoyi
*/
*/
@Configuration
@Configuration
@ConditionalOnProperty
(
value
=
"xss.enabled"
,
havingValue
=
"true"
)
public
class
FilterConfig
public
class
FilterConfig
{
{
@Value
(
"${xss.enabled}"
)
private
String
enabled
;
@Value
(
"${xss.excludes}"
)
@Value
(
"${xss.excludes}"
)
private
String
excludes
;
private
String
excludes
;
...
@@ -40,7 +39,6 @@ public class FilterConfig
...
@@ -40,7 +39,6 @@ public class FilterConfig
registration
.
setOrder
(
FilterRegistrationBean
.
HIGHEST_PRECEDENCE
);
registration
.
setOrder
(
FilterRegistrationBean
.
HIGHEST_PRECEDENCE
);
Map
<
String
,
String
>
initParameters
=
new
HashMap
<
String
,
String
>();
Map
<
String
,
String
>
initParameters
=
new
HashMap
<
String
,
String
>();
initParameters
.
put
(
"excludes"
,
excludes
);
initParameters
.
put
(
"excludes"
,
excludes
);
initParameters
.
put
(
"enabled"
,
enabled
);
registration
.
setInitParameters
(
initParameters
);
registration
.
setInitParameters
(
initParameters
);
return
registration
;
return
registration
;
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论