mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 16:23:42 +08:00 
			
		
		
		
	update 优化dataScope参数防止注入
This commit is contained in:
		@@ -68,6 +68,7 @@ public class DataScopeAspect
 | 
			
		||||
    @Before("dataScopePointCut()")
 | 
			
		||||
    public void doBefore(JoinPoint point) throws Throwable
 | 
			
		||||
    {
 | 
			
		||||
		clearDataScope(point);
 | 
			
		||||
        handleDataScope(point);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -144,18 +145,8 @@ public class DataScopeAspect
 | 
			
		||||
 | 
			
		||||
        if (StrUtil.isNotBlank(sqlString.toString()))
 | 
			
		||||
        {
 | 
			
		||||
            Object params = joinPoint.getArgs()[0];
 | 
			
		||||
            if (Validator.isNotNull(params))
 | 
			
		||||
            {
 | 
			
		||||
                try {
 | 
			
		||||
                    Method getParams = params.getClass().getDeclaredMethod("getParams", null);
 | 
			
		||||
                    Map<String, Object> invoke = (Map<String, Object>) getParams.invoke(params, null);
 | 
			
		||||
                    invoke.put(DATA_SCOPE, " AND (" + sqlString.substring(4) + ")");
 | 
			
		||||
                } catch (Exception e) {
 | 
			
		||||
                    e.printStackTrace();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
			putDataScope(joinPoint, " AND (" + sqlString.substring(4) + ")");
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -173,4 +164,30 @@ public class DataScopeAspect
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 拼接权限sql前先清空params.dataScope参数防止注入
 | 
			
		||||
	 */
 | 
			
		||||
	private void clearDataScope(final JoinPoint joinPoint)
 | 
			
		||||
	{
 | 
			
		||||
		Object params = joinPoint.getArgs()[0];
 | 
			
		||||
		if (Validator.isNotNull(params))
 | 
			
		||||
		{
 | 
			
		||||
			putDataScope(joinPoint, "");
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static void putDataScope(JoinPoint joinPoint, String sql) {
 | 
			
		||||
		Object params = joinPoint.getArgs()[0];
 | 
			
		||||
		if (Validator.isNotNull(params))
 | 
			
		||||
		{
 | 
			
		||||
			try {
 | 
			
		||||
				Method getParams = params.getClass().getDeclaredMethod("getParams", null);
 | 
			
		||||
				Map<String, Object> invoke = (Map<String, Object>) getParams.invoke(params, null);
 | 
			
		||||
				invoke.put(DATA_SCOPE, sql);
 | 
			
		||||
			} catch (Exception e) {
 | 
			
		||||
				// 方法未找到 不处理
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user