diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardConfiguration.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardConfiguration.java new file mode 100644 index 000000000..e0fa4bdcf --- /dev/null +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardConfiguration.java @@ -0,0 +1,25 @@ +package org.jeecg.config.firewall.interceptor; + +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +/** + * 单体模式注册内部接口拦截器 {@link InnerApiGuardInterceptor} + *
+ * 只在类路径不存在 jeecg-boot-starter-cloud 时(单体模式)生效;微服务模式下内部接口需供 Feign 调用,由网关拦截外部访问。 + * + * @author scott + * @since 2026-10-14 单体模式下内部接口可被任意登录用户直接调用 + */ +@Configuration +@ConditionalOnMissingClass("org.jeecg.config.JeecgCloudBaseConfig") +public class InnerApiGuardConfiguration implements WebMvcConfigurer { + + @Override + public void addInterceptors(InterceptorRegistry registry) { + registry.addInterceptor(new InnerApiGuardInterceptor()).addPathPatterns("/**").order(Ordered.HIGHEST_PRECEDENCE); + } +} diff --git a/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardInterceptor.java b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardInterceptor.java new file mode 100644 index 000000000..f617daaee --- /dev/null +++ b/jeecg-boot/jeecg-boot-base-core/src/main/java/org/jeecg/config/firewall/interceptor/InnerApiGuardInterceptor.java @@ -0,0 +1,67 @@ +package org.jeecg.config.firewall.interceptor; + +import com.alibaba.fastjson.JSON; +import lombok.extern.slf4j.Slf4j; +import org.jeecg.common.api.vo.Result; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.HandlerInterceptor; +import org.springframework.web.servlet.HandlerMapping; + +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.Set; + +/** + * 单体模式下禁止外部调用微服务内部接口 + *
+ * /sys/api、/airag/api、/online/api、/drag/api 等是提供给其它微服务 Feign 调用的内部接口,
+ * 单体模式下各模块为进程内调用,不需要对外暴露。其中部分接口位于依赖 jar 中无法直接修改,
+ * 因此按 Spring 实际匹配到的接口路径模板统一拦截(不受 URL 编码、大小写、重复斜杠等写法影响)。
+ *
+ * @author scott
+ * @since 2026-10-14 单体模式下内部接口可被任意登录用户直接调用(读写任意数据、读取数据源口令等)
+ */
+@Slf4j
+public class InnerApiGuardInterceptor implements HandlerInterceptor {
+
+ /**
+ * 微服务内部接口路径前缀
+ */
+ private static final String[] INNER_API_PREFIXES = {"/sys/api/", "/airag/api/", "/online/api/", "/drag/api/"};
+
+ /**
+ * 前端在用、需要放行的接口(Online 报表字典翻译)
+ */
+ private static final Set
+ * 仅供微服务 Feign 内部调用。单体模式下为进程内调用,无需对外暴露,
+ * 故只在类路径存在 jeecg-boot-starter-cloud(微服务模式)时加载(2026-10-14)
*
* @author sjlei
* @date 2025-12-30
*/
@RestController("airagBaseApiController")
+@ConditionalOnClass(name = "org.jeecg.config.JeecgCloudBaseConfig")
public class AiragBaseApiController implements IAiragBaseApi {
@Autowired
diff --git a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java
index 83ee17e31..0319657db 100644
--- a/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java
+++ b/jeecg-boot/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/api/controller/SystemApiController.java
@@ -15,6 +15,7 @@ import org.jeecg.common.system.vo.*;
import org.jeecg.modules.system.service.ISysUserService;
import org.jeecg.modules.system.service.impl.SysBaseApiImpl;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
@@ -26,11 +27,15 @@ import java.util.Set;
/**
* 服务化 system模块 对外接口请求类
+ *
+ * 仅供微服务 Feign 内部调用。单体模式下 ISysBaseAPI 为进程内调用,无需对外暴露,
+ * 故只在类路径存在 jeecg-boot-starter-cloud(微服务模式)时加载,防止 /sys/api/** 被普通登录用户直接调用(2026-10-14)
* @author: jeecg-boot
*/
@Slf4j
@RestController
@RequestMapping("/sys/api")
+@ConditionalOnClass(name = "org.jeecg.config.JeecgCloudBaseConfig")
public class SystemApiController {
@Autowired
diff --git a/jeecg-boot/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/filter/InnerApiBlockFilter.java b/jeecg-boot/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/filter/InnerApiBlockFilter.java
new file mode 100644
index 000000000..a01dadc3c
--- /dev/null
+++ b/jeecg-boot/jeecg-server-cloud/jeecg-cloud-gateway/src/main/java/org/jeecg/filter/InnerApiBlockFilter.java
@@ -0,0 +1,93 @@
+package org.jeecg.filter;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.cloud.gateway.filter.GatewayFilterChain;
+import org.springframework.cloud.gateway.filter.GlobalFilter;
+import org.springframework.core.Ordered;
+import org.springframework.core.io.buffer.DataBuffer;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.MediaType;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.stereotype.Component;
+import org.springframework.web.server.ServerWebExchange;
+import org.springframework.web.util.UriUtils;
+import reactor.core.publisher.Mono;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Locale;
+import java.util.Set;
+
+/**
+ * 禁止外部经网关访问微服务内部接口 /sys/api/**、/airag/api/**、/online/api/**、/drag/api/**
+ *
+ * 这些是各服务提供给其它微服务的 Feign 内部接口(含数据源明文口令、用户资料、任意表数据读写等),
+ * Feign 按服务名直连,不经过网关,因此在网关拦截不影响内部调用。
+ *
+ * @author scott
+ * @since 2026-10-14 微服务模式下外部请求可经网关直调内部接口
+ */
+@Slf4j
+@Component
+public class InnerApiBlockFilter implements GlobalFilter, Ordered {
+
+ /**
+ * 微服务内部接口路径前缀(小写)
+ */
+ private static final String[] INNER_API_PREFIXES = {"/sys/api/", "/airag/api/", "/online/api/", "/drag/api/"};
+
+ /**
+ * 放行的内部接口(规范化后的小写路径):前端字典翻译在用
+ */
+ private static final Set