Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fgqyxxlr
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
yaru
fgqyxxlr
Commits
f67d7179
Commit
f67d7179
authored
Aug 13, 2018
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xss加入配置文件
parent
e8eaeadb
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
25 deletions
+43
-25
src/main/java/com/ruoyi/common/constant/ShiroConstants.java
+1
-1
src/main/java/com/ruoyi/common/xss/XssFilter.java
+9
-11
src/main/java/com/ruoyi/framework/config/FilterConfig.java
+14
-3
src/main/java/com/ruoyi/framework/config/ShiroConfig.java
+3
-3
src/main/java/com/ruoyi/framework/shiro/web/filter/captcha/CaptchaValidateFilter.java
+5
-5
src/main/resources/application.yml
+10
-1
src/main/resources/templates/login.html
+1
-1
No files found.
src/main/java/com/ruoyi/common/constant/ShiroConstants.java
View file @
f67d7179
...
...
@@ -45,7 +45,7 @@ public interface ShiroConstants
/**
* 验证码开关
*/
public
static
final
String
CURRENT_E
BABLED
=
"captchaEb
abled"
;
public
static
final
String
CURRENT_E
NABLED
=
"captchaEn
abled"
;
/**
* 验证码开关
...
...
src/main/java/com/ruoyi/common/xss/XssFilter.java
View file @
f67d7179
...
...
@@ -11,7 +11,6 @@ import javax.servlet.FilterConfig;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.annotation.WebFilter
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
com.ruoyi.common.utils.StringUtils
;
...
...
@@ -21,7 +20,6 @@ import com.ruoyi.common.utils.StringUtils;
*
* @author ruoyi
*/
@WebFilter
(
filterName
=
"xssFilter"
,
urlPatterns
=
"/system/*"
)
public
class
XssFilter
implements
Filter
{
/**
...
...
@@ -32,14 +30,14 @@ public class XssFilter implements Filter
/**
* xss过滤开关
*/
public
boolean
xssEb
abled
=
false
;
public
boolean
en
abled
=
false
;
@Override
public
void
init
(
FilterConfig
filterConfig
)
throws
ServletException
{
String
tempExcludes
=
filterConfig
.
getInitParameter
(
"excludes"
);
String
temp
XssEbabled
=
filterConfig
.
getInitParameter
(
"xssEb
abled"
);
if
(
tempExcludes
!=
null
)
String
temp
Enabled
=
filterConfig
.
getInitParameter
(
"en
abled"
);
if
(
StringUtils
.
isNotEmpty
(
tempExcludes
)
)
{
String
[]
url
=
tempExcludes
.
split
(
","
);
for
(
int
i
=
0
;
url
!=
null
&&
i
<
url
.
length
;
i
++)
...
...
@@ -47,9 +45,9 @@ public class XssFilter implements Filter
excludes
.
add
(
url
[
i
]);
}
}
if
(
StringUtils
.
isNotEmpty
(
temp
XssEb
abled
))
if
(
StringUtils
.
isNotEmpty
(
temp
En
abled
))
{
xssEbabled
=
Boolean
.
valueOf
(
tempXssEb
abled
);
enabled
=
Boolean
.
valueOf
(
tempEn
abled
);
}
}
...
...
@@ -70,13 +68,13 @@ public class XssFilter implements Filter
private
boolean
handleExcludeURL
(
HttpServletRequest
request
,
HttpServletResponse
response
)
{
if
(
excludes
==
null
||
excludes
.
isEmpty
()
)
if
(
!
enabled
)
{
return
fals
e
;
return
tru
e
;
}
if
(
!
xssEbabled
)
if
(
excludes
==
null
||
excludes
.
isEmpty
()
)
{
return
tru
e
;
return
fals
e
;
}
String
url
=
request
.
getServletPath
();
for
(
String
pattern
:
excludes
)
...
...
src/main/java/com/ruoyi/framework/config/FilterConfig.java
View file @
f67d7179
...
...
@@ -2,10 +2,12 @@ package com.ruoyi.framework.config;
import
java.util.Map
;
import
javax.servlet.DispatcherType
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.boot.web.servlet.FilterRegistrationBean
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
com.google.common.collect.Maps
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.xss.XssFilter
;
/**
...
...
@@ -16,6 +18,15 @@ import com.ruoyi.common.xss.XssFilter;
@Configuration
public
class
FilterConfig
{
@Value
(
"${xss.enabled}"
)
private
String
enabled
;
@Value
(
"${xss.excludes}"
)
private
String
excludes
;
@Value
(
"${xss.urlPatterns}"
)
private
String
urlPatterns
;
@SuppressWarnings
({
"rawtypes"
,
"unchecked"
})
@Bean
public
FilterRegistrationBean
xssFilterRegistration
()
...
...
@@ -23,12 +34,12 @@ public class FilterConfig
FilterRegistrationBean
registration
=
new
FilterRegistrationBean
();
registration
.
setDispatcherTypes
(
DispatcherType
.
REQUEST
);
registration
.
setFilter
(
new
XssFilter
());
registration
.
addUrlPatterns
(
"/*"
);
registration
.
addUrlPatterns
(
StringUtils
.
split
(
urlPatterns
,
","
)
);
registration
.
setName
(
"xssFilter"
);
registration
.
setOrder
(
Integer
.
MAX_VALUE
);
Map
<
String
,
String
>
initParameters
=
Maps
.
newHashMap
();
initParameters
.
put
(
"excludes"
,
"/system/notice/*,/img/*,/css/*,/fonts/*,/js/*,/ajax/*,/ruoyi/*"
);
initParameters
.
put
(
"
xssEbabled"
,
"false"
);
initParameters
.
put
(
"excludes"
,
excludes
);
initParameters
.
put
(
"
enabled"
,
enabled
);
registration
.
setInitParameters
(
initParameters
);
return
registration
;
}
...
...
src/main/java/com/ruoyi/framework/config/ShiroConfig.java
View file @
f67d7179
...
...
@@ -46,8 +46,8 @@ public class ShiroConfig
private
int
validationInterval
;
// 验证码开关
@Value
(
"${shiro.user.captchaE
b
abled}"
)
private
boolean
captchaE
b
abled
;
@Value
(
"${shiro.user.captchaE
n
abled}"
)
private
boolean
captchaE
n
abled
;
// 验证码类型
@Value
(
"${shiro.user.captchaType}"
)
...
...
@@ -297,7 +297,7 @@ public class ShiroConfig
public
CaptchaValidateFilter
captchaValidateFilter
()
{
CaptchaValidateFilter
captchaValidateFilter
=
new
CaptchaValidateFilter
();
captchaValidateFilter
.
setCaptchaE
babled
(
captchaEb
abled
);
captchaValidateFilter
.
setCaptchaE
nabled
(
captchaEn
abled
);
captchaValidateFilter
.
setCaptchaType
(
captchaType
);
return
captchaValidateFilter
;
}
...
...
src/main/java/com/ruoyi/framework/shiro/web/filter/captcha/CaptchaValidateFilter.java
View file @
f67d7179
...
...
@@ -20,16 +20,16 @@ public class CaptchaValidateFilter extends AccessControlFilter
/**
* 是否开启验证码
*/
private
boolean
captchaE
b
abled
=
true
;
private
boolean
captchaE
n
abled
=
true
;
/**
* 验证码类型
*/
private
String
captchaType
=
"math"
;
public
void
setCaptchaE
babled
(
boolean
captchaEb
abled
)
public
void
setCaptchaE
nabled
(
boolean
captchaEn
abled
)
{
this
.
captchaE
babled
=
captchaEb
abled
;
this
.
captchaE
nabled
=
captchaEn
abled
;
}
public
void
setCaptchaType
(
String
captchaType
)
...
...
@@ -40,7 +40,7 @@ public class CaptchaValidateFilter extends AccessControlFilter
@Override
public
boolean
onPreHandle
(
ServletRequest
request
,
ServletResponse
response
,
Object
mappedValue
)
throws
Exception
{
request
.
setAttribute
(
ShiroConstants
.
CURRENT_E
BABLED
,
captchaEb
abled
);
request
.
setAttribute
(
ShiroConstants
.
CURRENT_E
NABLED
,
captchaEn
abled
);
request
.
setAttribute
(
ShiroConstants
.
CURRENT_TYPE
,
captchaType
);
return
super
.
onPreHandle
(
request
,
response
,
mappedValue
);
}
...
...
@@ -51,7 +51,7 @@ public class CaptchaValidateFilter extends AccessControlFilter
{
HttpServletRequest
httpServletRequest
=
(
HttpServletRequest
)
request
;
// 验证码禁用 或不是表单提交 允许访问
if
(
captchaE
b
abled
==
false
||
!
"post"
.
equals
(
httpServletRequest
.
getMethod
().
toLowerCase
()))
if
(
captchaE
n
abled
==
false
||
!
"post"
.
equals
(
httpServletRequest
.
getMethod
().
toLowerCase
()))
{
return
true
;
}
...
...
src/main/resources/application.yml
View file @
f67d7179
...
...
@@ -40,6 +40,7 @@ spring:
thymeleaf
:
mode
:
HTML
encoding
:
utf-8
# 禁用缓存
cache
:
false
messages
:
#国际化资源文件路径
...
...
@@ -82,7 +83,7 @@ shiro:
# 首页地址
indexUrl
:
/index
# 验证码开关
captchaE
b
abled
:
true
captchaE
n
abled
:
true
# 验证码类型 math 数组计算 char 字符
captchaType
:
math
cookie
:
...
...
@@ -101,6 +102,14 @@ shiro:
dbSyncPeriod
:
1
# 相隔多久检查一次session的有效性,默认就是10分钟
validationInterval
:
10
# 防止XSS攻击
xss
:
# 过滤开关
enabled
:
true
# 排除链接(多个用逗号分隔)
excludes
:
/system/notice/*
# 匹配链接
urlPatterns
:
/system/*,/monitor/*,/tool/*
# 代码生成
gen
:
# 作者
...
...
src/main/resources/templates/login.html
View file @
f67d7179
...
...
@@ -50,7 +50,7 @@
<p
class=
"m-t-md"
>
你若不离不弃,我必生死相依
</p>
<input
type=
"text"
name=
"username"
class=
"form-control uname"
placeholder=
"用户名"
value=
"admin"
/>
<input
type=
"password"
name=
"password"
class=
"form-control pword m-b"
placeholder=
"密码"
value=
"admin123"
/>
<div
class=
"row"
th:if=
"${captchaE
b
abled==true}"
>
<div
class=
"row"
th:if=
"${captchaE
n
abled==true}"
>
<div
class=
"col-xs-6"
>
<input
type=
"text"
name=
"validateCode"
class=
"form-control code"
placeholder=
"验证码"
maxlength=
"5"
>
</div>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment