Skip to content
This repository was archived by the owner on Jul 10, 2024. It is now read-only.

Commit 4cd2af1

Browse files
committed
SUBMARINE-1361. Fix Submarine SQL injection vulnerability
### What is this PR for? Currently a SQL injection vulnerability has been checked in submarine and the relevant part of the `like` statement in mybatis needs to be fixed. ### What type of PR is it? Bug Fix ### Todos * [x] - replace `like` statement to `concat('%', #{param}, '%')` ### What is the Jira issue? https://issues.apache.org/jira/browse/SUBMARINE-1361 ### How should this be tested? Added a test case verification code in `submarine-server/server-database/src/test/java/org/apache/submarine/server/database/workbench/database/service/SysUserServiceTest.java` ### Screenshots (if appropriate) NA ### Questions: * Do the license files need updating? No * Are there breaking changes for older versions? No * Does this need new documentation? No Author: cdmikechen <[email protected]> Signed-off-by: cdmikechen <[email protected]> Closes #1037 from cdmikechen/SUBMARINE-1361 and squashes the following commits: 34fb34b [cdmikechen] Avoid sql injection
1 parent 58cf1d5 commit 4cd2af1

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

submarine-server/server-database/src/main/resources/org/apache/submarine/database/mappers/SysDeptMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
SELECT a.*, b.dept_name AS parent_name
4343
FROM sys_department a LEFT JOIN sys_department b ON a.parent_code=b.dept_code
4444
WHERE 1=1
45-
<if test="deptCode!=null and deptCode!=''"> AND a.`dept_code` like '%${deptCode}%' </if>
46-
<if test="deptName!=null and deptName!=''"> AND a.`dept_name` like '%${deptName}%' </if>
45+
<if test="deptCode!=null and deptCode!=''"> AND a.`dept_code` like concat('%', #{deptCode}, '%')</if>
46+
<if test="deptName!=null and deptName!=''"> AND a.`dept_name` like concat('%', #{deptName}, '%')</if>
4747
ORDER BY a.sort_order
4848
</select>
4949

submarine-server/server-database/src/main/resources/org/apache/submarine/database/mappers/SysDictItemMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<select id="selectAll" resultMap="resultMap">
3232
SELECT * FROM sys_dict_item WHERE 1 = 1
3333
<if test="dictCode!=null and dictCode!=''"> AND `dict_code` = #{dictCode}</if>
34-
<if test="itemCode!=null and itemCode!=''"> AND `item_code` like '%${itemCode}%'</if>
35-
<if test="itemName!=null and itemName!=''"> AND `item_name` like '%${itemName}%'</if>
34+
<if test="itemCode!=null and itemCode!=''"> AND `item_code` like concat('%', #{itemCode}, '%')</if>
35+
<if test="itemName!=null and itemName!=''"> AND `item_name` like concat('%', #{itemName}, '%')</if>
3636
ORDER BY sort_order
3737
</select>
3838
<resultMap id="resultMap" type="org.apache.submarine.server.database.workbench.entity.SysDictItemEntity" extends="BaseEntityResultMap">

submarine-server/server-database/src/main/resources/org/apache/submarine/database/mappers/SysDictMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
<select id="selectAll" parameterType="java.util.Map" resultMap="resultMap">
3232
SELECT * FROM sys_dict
3333
WHERE 1=1
34-
<if test="dictCode!=null and dictCode!=''">AND `dict_code` like '%${dictCode}%'</if>
35-
<if test="dictName!=null and dictName!=''">AND `dict_name` like '%${dictName}%'</if>
34+
<if test="dictCode!=null and dictCode!=''">AND `dict_code` like concat('%', #{dictCode}, '%')</if>
35+
<if test="dictName!=null and dictName!=''">AND `dict_name` like concat('%', #{dictName}, '%')</if>
3636
ORDER BY id
3737
</select>
3838
<resultMap id="resultMap" type="org.apache.submarine.server.database.workbench.entity.SysDictEntity" extends="BaseEntityResultMap">

submarine-server/server-database/src/main/resources/org/apache/submarine/database/mappers/SysUserMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
SELECT a.*, b.dept_name FROM sys_user a LEFT JOIN sys_department b ON a.dept_code = b.dept_code
4040
WHERE 1 = 1
4141
<if test="deptCode!=null and deptCode!=''"> AND a.`dept_code` = #{deptCode}</if>
42-
<if test="userName!=null and userName!=''"> AND a.`user_name` like '%${userName}%'</if>
43-
<if test="email!=null and email!=''"> AND a.`email` like '%${email}%'</if>
42+
<if test="userName!=null and userName!=''"> AND a.`user_name` like concat('%', #{userName}, '%')</if>
43+
<if test="email!=null and email!=''"> AND a.`email` like concat('%', #{email}, '%')</if>
4444
ORDER BY a.create_time
4545
</select>
4646

submarine-server/server-database/src/test/java/org/apache/submarine/server/database/workbench/database/service/SysUserServiceTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ public void addUserTest() throws Exception {
7878
10);
7979
LOG.debug("userList.size():{}", userList.size());
8080
assertEquals(userList.size(), 1);
81+
82+
// Avoid sql injection.
83+
// Issue: https://issues.apache.org/jira/browse/SUBMARINE-1361
84+
List<SysUserEntity> sqlInjectTestList = userService.queryPageList(
85+
String.format("%s' or 1=1 or 1='", sysUser.getUserName()),
86+
null,
87+
null,
88+
null,
89+
null,
90+
0,
91+
10);
92+
assertEquals("SQL Injection Vulnerability Detected!", sqlInjectTestList.size(), 0);
93+
8194
SysUserEntity user = userList.get(0);
8295

8396
assertEquals(sysUser.getEmail(), user.getEmail());

0 commit comments

Comments
 (0)