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
8a37d2ae
Commit
8a37d2ae
authored
Feb 28, 2019
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
检查字符,防止注入绕过
parent
9c50dd8c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
12 deletions
+21
-12
ruoyi-common/src/main/java/com/ruoyi/common/page/PageDomain.java
+2
-6
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
+17
-5
ruoyi-framework/src/main/java/com/ruoyi/framework/web/base/BaseController.java
+2
-1
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/page/PageDomain.java
View file @
8a37d2ae
package
com
.
ruoyi
.
common
.
page
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.sql.SqlUtil
;
/**
* 分页数据
...
...
@@ -12,14 +11,11 @@ public class PageDomain
{
/** 当前记录起始索引 */
private
Integer
pageNum
;
/** 每页显示记录数 */
private
Integer
pageSize
;
/** 排序列 */
private
String
orderByColumn
;
/** 排序的方向 "desc" 或者 "asc". */
private
String
isAsc
;
public
String
getOrderBy
()
...
...
@@ -58,7 +54,7 @@ public class PageDomain
public
void
setOrderByColumn
(
String
orderByColumn
)
{
this
.
orderByColumn
=
SqlUtil
.
escapeSql
(
orderByColumn
)
;
this
.
orderByColumn
=
orderByColumn
;
}
public
String
getIsAsc
()
...
...
@@ -68,6 +64,6 @@ public class PageDomain
public
void
setIsAsc
(
String
isAsc
)
{
this
.
isAsc
=
SqlUtil
.
escapeSql
(
isAsc
)
;
this
.
isAsc
=
isAsc
;
}
}
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
View file @
8a37d2ae
...
...
@@ -10,15 +10,27 @@ import com.ruoyi.common.utils.StringUtils;
public
class
SqlUtil
{
/**
*
防止sql注入 替换危险字符
*
仅支持字母、数字、下划线、空格、逗号(支持多个字段排序)
*/
public
static
String
escapeSql
(
String
value
)
public
static
String
SQL_PATTERN
=
"[a-zA-Z0-9_\\ \\,]+"
;
/**
* 检查字符,防止注入绕过
*/
public
static
String
escapeOrderBySql
(
String
value
)
{
if
(
StringUtils
.
isNotEmpty
(
value
))
if
(
StringUtils
.
isNotEmpty
(
value
)
&&
!
isValidOrderBySql
(
value
)
)
{
value
=
value
.
replaceAll
(
"\\("
,
""
);
value
=
value
.
replaceAll
(
"\\)"
,
""
);
return
StringUtils
.
EMPTY
;
}
return
value
;
}
/**
* 验证 order by 语法是否符合规范
*/
public
static
boolean
isValidOrderBySql
(
String
value
)
{
return
value
.
matches
(
SQL_PATTERN
);
}
}
ruoyi-framework/src/main/java/com/ruoyi/framework/web/base/BaseController.java
View file @
8a37d2ae
...
...
@@ -13,6 +13,7 @@ import com.ruoyi.common.page.TableDataInfo;
import
com.ruoyi.common.page.TableSupport
;
import
com.ruoyi.common.utils.DateUtils
;
import
com.ruoyi.common.utils.StringUtils
;
import
com.ruoyi.common.utils.sql.SqlUtil
;
import
com.ruoyi.framework.util.ShiroUtils
;
import
com.ruoyi.system.domain.SysUser
;
...
...
@@ -50,7 +51,7 @@ public class BaseController
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
StringUtils
.
isNotNull
(
pageNum
)
&&
StringUtils
.
isNotNull
(
pageSize
))
{
String
orderBy
=
pageDomain
.
getOrderBy
(
);
String
orderBy
=
SqlUtil
.
escapeOrderBySql
(
pageDomain
.
getOrderBy
()
);
PageHelper
.
startPage
(
pageNum
,
pageSize
,
orderBy
);
}
}
...
...
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