Browse Source

fix: JWT白名单改路径边界匹配防止verify-password被前缀放行 + 补登录必需拦截

Xiaogang Liao 3 weeks ago
parent
commit
344cc7ba79

+ 5 - 2
cfc-backend/src/main/java/com/etotem/cfc/config/JwtInterceptor.java

@@ -68,7 +68,8 @@ public class JwtInterceptor implements HandlerInterceptor {
 
     // 必须登录才能访问的路径:anonymous 访问直接 401(这些接口消耗微信配额/写数据/扣积分)
     private static final String[] LOGIN_REQUIRED_PATHS = {
-        "/api/share/qrcode"     // 生成海报小程序码:anonymous 会反复触发微信 access_token 失效("not latest")
+        "/api/share/qrcode",        // 生成海报小程序码:anonymous 会反复触发微信 access_token 失效("not latest")
+        "/api/auth/verify-password" // 密码验证:属凭证操作,必须登录(防 /api/auth/verify 前缀碰撞白名单放行)
     };
 
     @Override
@@ -80,7 +81,9 @@ public class JwtInterceptor implements HandlerInterceptor {
 
         String path = request.getRequestURI();
         for (String publicPath : PUBLIC_PATHS) {
-            if (path.equals(publicPath) || path.startsWith(publicPath)) {
+            String boundaryPath = publicPath.endsWith("/**")
+                    ? publicPath.substring(0, publicPath.length() - 3) : publicPath;
+            if (path.equals(publicPath) || path.startsWith(boundaryPath + "/")) {
                 return true;
             }
         }