Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
finance-manage
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
finance-oa
finance-manage
Commits
fd3a699a
Commit
fd3a699a
authored
Dec 21, 2021
by
RuoYi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
SQL工具类新增检查关键字方法
parent
c28aa299
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
0 deletions
+24
-0
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
...mon/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
+24
-0
No files found.
ruoyi-common/src/main/java/com/ruoyi/common/utils/sql/SqlUtil.java
View file @
fd3a699a
...
...
@@ -10,6 +10,11 @@ import com.ruoyi.common.utils.StringUtils;
*/
public
class
SqlUtil
{
/**
* 定义常用的 sql关键字
*/
public
static
String
SQL_REGEX
=
"select |insert |delete |update |drop |count |exec |chr |mid |master |truncate |char |and |declare "
;
/**
* 仅支持字母、数字、下划线、空格、逗号、小数点(支持多个字段排序)
*/
...
...
@@ -34,4 +39,23 @@ public class SqlUtil
{
return
value
.
matches
(
SQL_PATTERN
);
}
/**
* SQL关键字检查
*/
public
static
void
filterKeyword
(
String
value
)
{
if
(
StringUtils
.
isEmpty
(
value
))
{
return
;
}
String
[]
sqlKeywords
=
StringUtils
.
split
(
SQL_REGEX
,
"\\|"
);
for
(
int
i
=
0
;
i
<
sqlKeywords
.
length
;
i
++)
{
if
(
StringUtils
.
indexOfIgnoreCase
(
value
,
sqlKeywords
[
i
])
>
-
1
)
{
throw
new
UtilException
(
"参数存在SQL注入风险"
);
}
}
}
}
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