File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
main/java/com/github/pagehelper/util
test/java/com/github/pagehelper/util Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public class SqlSafeUtil {
3636 * 参考: mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/sql/SqlInjectionUtils.java
3737 */
3838 private static final Pattern SQL_SYNTAX_PATTERN = Pattern .compile ("(insert|delete|update|select|create|drop|truncate|grant|alter|deny|revoke|call|execute|exec|declare|show|rename|set)" +
39- ".+ (into|from|set|where|table|database|view|index|on|cursor|procedure|trigger|for|password|union|and|or)" , Pattern .CASE_INSENSITIVE );
39+ "\\ s+.* (into|from|set|where|table|database|view|index|on|cursor|procedure|trigger|for|password|union|and|or)|(select \\ s* \\ * \\ s*from \\ s+ )" , Pattern .CASE_INSENSITIVE );
4040 /**
4141 * 使用'、;或注释截断SQL检查正则
4242 * <p>
Original file line number Diff line number Diff line change 1+ package com .github .pagehelper .util ;
2+
3+ import org .junit .Test ;
4+
5+ import static org .junit .Assert .*;
6+
7+ public class SqlSafeUtilTest {
8+
9+ @ Test
10+ public void check () {
11+ assertSql (true , "insert into xx" );
12+ // 无空格
13+ assertSql (false , "insertxxinto xx" );
14+ assertSql (false , "insert_into" );
15+ assertSql (true , "SELECT aa FROM user" );
16+ // 无空格
17+ assertSql (true , "SELECT*FROM user" );
18+ // 左空格
19+ assertSql (true , "SELECT *FROM user" );
20+ // 右空格
21+ assertSql (true , "SELECT* FROM user" );
22+ // 左tab
23+ assertSql (true , "SELECT *FROM user" );
24+ // 右tab
25+ assertSql (true , "SELECT* FROM user" );
26+ assertSql (false , "SELECT*FROMuser" );
27+
28+ // 验证 issue #707 问题
29+ assertSql (false , "databaseType desc,orderNum desc" );
30+ }
31+
32+ private void assertSql (boolean injection , String sql ) {
33+ assertEquals (injection , SqlSafeUtil .check (sql ));
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments