From af479c78385fc3ebdfd345ae12a42858b0f79d2e Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: Thu, 27 May 2021 21:13:01 +0800
Subject: [PATCH] 修复两处存在SQL注入漏洞问题

---
 ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java |   14 ++++++++++++++
 ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml                            |    2 +-
 2 files changed, 15 insertions(+), 1 deletions(-)

diff --git a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
index 72aafcd..453c79c 100644
--- a/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
+++ b/ruoyi-common/ruoyi-common-datascope/src/main/java/com/ruoyi/common/datascope/aspect/DataScopeAspect.java
@@ -68,6 +68,7 @@
     @Before("dataScopePointCut()")
     public void doBefore(JoinPoint point) throws Throwable
     {
+        clearDataScope(point);
         handleDataScope(point);
     }
 
@@ -169,4 +170,17 @@
         }
         return null;
     }
+
+    /**
+     * 拼接权限sql前先清空params.dataScope参数防止注入
+     */
+    private void clearDataScope(final JoinPoint joinPoint)
+    {
+        Object params = joinPoint.getArgs()[0];
+        if (StringUtils.isNotNull(params) && params instanceof BaseEntity)
+        {
+            BaseEntity baseEntity = (BaseEntity) params;
+            baseEntity.getParams().put(DATA_SCOPE, "");
+        }
+    }
 }
diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
index f8cdf67..17fecaa 100644
--- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
+++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/SysDeptMapper.xml
@@ -147,7 +147,7 @@
  	        <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
  	        update_time = sysdate()
         </set>
- 	    where dept_id in (${ancestors})
+ 	    where find_in_set(#{deptId}, ancestors)
 	</update>
 	
 	<delete id="deleteDeptById" parameterType="Long">

--
Gitblit v1.9.3