Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
e0ff0092
Commit
e0ff0092
authored
Feb 25, 2018
by
xiandafu
Browse files
xss
parent
7fecf4df
Changes
2
Hide whitespace changes
Inline
Side-by-side
admin-core/src/main/java/com/ibeetl/admin/core/conf/BeetlConf.java
View file @
e0ff0092
...
...
@@ -31,6 +31,7 @@ import com.ibeetl.admin.core.util.beetl.OrgFunction;
import
com.ibeetl.admin.core.util.beetl.RoleFunction
;
import
com.ibeetl.admin.core.util.beetl.SearchCondtionFunction
;
import
com.ibeetl.admin.core.util.beetl.SysFunctionTreeFunction
;
import
com.ibeetl.admin.core.util.beetl.XXSDefenderFormat
;
import
com.ibeetl.admin.core.web.query.QueryParser
;
import
com.ibeetl.starter.BeetlTemplateCustomize
;
import
com.ibeetl.starter.ObjectMapperJsonUtil
;
...
...
@@ -103,6 +104,7 @@ public class BeetlConf {
groupTemplate
.
registerFunction
(
"core.dictLevel"
,
dictUpQueryFunction
);
groupTemplate
.
registerFunction
(
"core.dictListByValue"
,
dictQueryByValueFunction
);
groupTemplate
.
registerFunction
(
"core.roles"
,
roleFunction
);
groupTemplate
.
registerFormat
(
"xss"
,
new
XXSDefenderFormat
());
// 模板页面判断是否有按钮权限,比如canAccess
groupTemplate
.
registerFunction
(
"canAccess"
,
new
Function
()
{
...
...
admin-core/src/main/java/com/ibeetl/admin/core/util/beetl/XXSDefenderFormat.java
0 → 100644
View file @
e0ff0092
package
com.ibeetl.admin.core.util.beetl
;
import
org.apache.commons.lang3.StringEscapeUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.beetl.core.Format
;
public
class
XXSDefenderFormat
implements
Format
{
@Override
public
Object
format
(
Object
data
,
String
pattern
)
{
if
(
data
==
null
){
return
data
;
}
if
(
data
instanceof
String
){
String
js
=
(
String
)
data
;
String
str
=
StringEscapeUtils
.
escapeHtml4
(
js
);
if
(
StringUtils
.
isNotEmpty
(
pattern
)){
int
len
=
Integer
.
parseInt
(
pattern
);
if
(
str
.
length
()>
len
){
str
=
str
.
substring
(
0
,
len
);
}
}
return
str
;
}
else
{
return
data
;
}
}
public
static
void
main
(
String
[]
args
){
String
js
=
"中文<script>hi</script><h5></h5>"
;
System
.
out
.
println
(
js
);
js
=
StringEscapeUtils
.
escapeHtml4
(
js
);
System
.
out
.
println
(
js
);
}
}
Write
Preview
Supports
Markdown
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