From f2b5192669aa7be303e14efd161f499cb8c16f71 Mon Sep 17 00:00:00 2001 From: scott Date: Tue, 27 Oct 2026 06:38:41 -0400 Subject: [PATCH] =?UTF-8?q?=E3=80=90GHSA-9h56=E3=80=91=E7=BD=91=E5=85=B3?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=8E=A5=E5=8F=A3=E8=A1=A5=E6=9D=83=E9=99=90?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=EF=BC=9Alist=E3=80=81clearRedis=E3=80=81dele?= =?UTF-8?q?teList=20=E5=A2=9E=E5=8A=A0=E6=9D=83=E9=99=90=E6=B3=A8=E8=A7=A3?= =?UTF-8?q?=EF=BC=9BupdateAll=20=E9=98=B2=20SpEL=20=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- .../controller/SysGatewayRouteController.java | 5 ++ .../impl/SysGatewayRouteServiceImpl.java | 61 +++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysGatewayRouteController.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysGatewayRouteController.java index 9af4c944b..8332af5cf 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysGatewayRouteController.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/controller/SysGatewayRouteController.java @@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang.StringUtils; +import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.jeecg.common.api.vo.Result; import org.jeecg.common.system.base.controller.JeecgController; @@ -41,6 +42,8 @@ public class SysGatewayRouteController extends JeecgController queryPageList(SysGatewayRoute sysGatewayRoute) { LambdaQueryWrapper query = new LambdaQueryWrapper<>(); @@ -59,6 +62,7 @@ public class SysGatewayRouteController extends JeecgController clearRedis() { sysGatewayRouteService.clearRedis(); @@ -82,6 +86,7 @@ public class SysGatewayRouteController extends JeecgController> deleteList(HttpServletRequest request) { Result> result = new Result<>(); diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java index 99c89307e..a39ad34ae 100644 --- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java +++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/system/service/impl/SysGatewayRouteServiceImpl.java @@ -3,6 +3,7 @@ package org.jeecg.modules.system.service.impl; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -11,6 +12,7 @@ import org.jeecg.common.base.BaseMap; import org.jeecg.common.constant.CacheConstant; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.constant.GlobalConstants; +import org.jeecg.common.exception.JeecgBootException; import org.jeecg.common.util.oConvertUtils; import org.jeecg.modules.system.entity.SysGatewayRoute; import org.jeecg.modules.system.mapper.SysGatewayRouteMapper; @@ -24,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; +import java.util.regex.Pattern; /** * @Description: gateway路由管理 @@ -40,6 +43,14 @@ public class SysGatewayRouteServiceImpl extends ServiceImpl ROUTE_URI_SCHEMES = List.of("lb://", "lb:ws://", "lb:wss://", "http://", "https://", "ws://", "wss://", "forward:", "no://op"); + /** + * 允许的 SpEL 写法:仅 Bean 引用,如限流过滤器的 #{@ipKeyResolver} + */ + private static final Pattern SPEL_BEAN_REF = Pattern.compile("#\\{@[A-Za-z_$][\\w$]*}"); @Override public void addRoute2Redis(String key) { List ls = this.list(new LambdaQueryWrapper()); @@ -62,6 +73,12 @@ public class SysGatewayRouteServiceImpl extends ServiceImpl getDeletelist() { return baseMapper.queryDeleteList(); } + + /** + * 校验路由配置:Spring Cloud Gateway 会把 #{...} 形式的参数当作 SpEL 执行,uri 决定转发目标 + * + * @param uri 路由地址 + * @param predicates 路由断言(JSON 数组字符串) + * @param filters 过滤器(JSON 数组字符串) + * @author scott + * @since 2026-10-26 【GHSA-9h56-m6g6-7g8r】路由配置 SpEL 注入防护 + */ + private static void checkRouteConfig(String uri, String predicates, String filters) { + if (oConvertUtils.isNotEmpty(uri)) { + String lowerUri = uri.trim().toLowerCase(); + if (ROUTE_URI_SCHEMES.stream().noneMatch(lowerUri::startsWith)) { + throw new JeecgBootException("路由地址只支持 lb://、http(s)://、ws(s)://、forward: 协议"); + } + } + checkNoSpel(predicates, "路由条件"); + checkNoSpel(filters, "过滤器"); + } + + /** + * 断言/过滤器参数中禁止出现 SpEL 表达式(仅放行 #{@beanName} 引用)。 + * 先按 JSON 解析再序列化,避免用 Unicode 转义写法绕过 + * + * @param text JSON 数组字符串 + * @param label 提示名称 + * @author scott + * @since 2026-10-26 【GHSA-9h56-m6g6-7g8r】路由配置 SpEL 注入防护 + */ + private static void checkNoSpel(String text, String label) { + if (oConvertUtils.isEmpty(text)) { + return; + } + String normalized; + try { + normalized = JSONArray.parseArray(text).toJSONString(); + } catch (Exception e) { + throw new JeecgBootException(label + "格式错误"); + } + if (SPEL_BEAN_REF.matcher(normalized).replaceAll("").contains("#{")) { + throw new JeecgBootException(label + "参数不允许使用表达式 #{...}(仅支持 #{@beanName} 引用)"); + } + } }