Explorar el Código

fix(security): 恢复 CORS 通配,避免生产域名不匹配导致整站无法访问

Constraint: 优先恢复生产可用性,CORS 收紧可后续再按域名白名单做
Confidence: high
Scope-risk: narrow
Co-authored-by: Cursor <cursoragent@cursor.com>
“wuzhen” hace 4 días
padre
commit
fa6bf7aea2

+ 0 - 2
backend/ruoyi-admin/src/main/resources/application.yml

@@ -130,8 +130,6 @@ sa-token:
 
 # security配置
 security:
-  # 允许跨域访问的来源(支持 * 通配子域名与 [*] 通配端口);前端均经 nginx 同源访问 /prod-api,新增域名时在此补充
-  cors-allowed-origins: "http://*.hzdyjsxy.cn:[*],https://*.hzdyjsxy.cn:[*],http://localhost:[*],http://127.0.0.1:[*]"
   # 排除路径(P0:已下线 Swagger/api-docs,不再加入白名单)
   excludes:
     - /*.html

+ 3 - 5
backend/ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/config/ResourcesConfig.java

@@ -1,7 +1,5 @@
 package org.dromara.common.web.config;
 
-import java.util.List;
-import org.springframework.beans.factory.annotation.Value;
 import org.dromara.common.web.handler.GlobalExceptionHandler;
 import org.dromara.common.web.interceptor.PlusWebInvokeTimeInterceptor;
 import org.springframework.boot.autoconfigure.AutoConfiguration;
@@ -35,11 +33,11 @@ public class ResourcesConfig implements WebMvcConfigurer {
      * 跨域配置
      */
     @Bean
-    public CorsFilter corsFilter(@Value("${security.cors-allowed-origins:http://localhost:[*],http://127.0.0.1:[*]}") List<String> allowedOrigins) {
+    public CorsFilter corsFilter() {
         CorsConfiguration config = new CorsConfiguration();
         config.setAllowCredentials(true);
-        // 设置访问源地址(仅允许配置的本校域名,禁止回显任意 Origin)
-        allowedOrigins.forEach(config::addAllowedOriginPattern);
+        // 设置访问源地址(恢复为原通配,避免生产域名/IP 不匹配导致整站接口被浏览器拦截)
+        config.addAllowedOriginPattern("*");
         // 设置访问源请求头
         config.addAllowedHeader("*");
         // 设置访问源请求方法