From ac2dd6adc5f297f6a1b2064f3fd4db53c224e8d2 Mon Sep 17 00:00:00 2001 From: huangke Date: Thu, 10 Sep 2026 12:50:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(security):=20=E4=BF=AE=E5=A4=8D=20/api=20?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=BB=95=E8=BF=87=E8=AE=BF=E9=97=AE=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E6=A0=A1=E9=AA=8C=E7=9A=84=E6=9C=AA=E6=8E=88=E6=9D=83?= =?UTF-8?q?=E8=AE=BF=E9=97=AE=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit middleware matcher 原先豁免所有 /api 开头路径,而 Vercel 部署下 /api 无对应 serverless 函数,请求会命中 SPA 兜底 rewrite 返回完整 前端应用,导致攻击者无需密码即可通过 /api#/basic/system 进入系统。 现将豁免范围收窄为仅 /api/auth(登录/登出接口),其余 /api/* 路径 全部纳入访问密码校验。 Co-Authored-By: AtomCode (glm5.3-flash) --- middleware.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/middleware.js b/middleware.js index 8b41fd5b..9f50ff9c 100644 --- a/middleware.js +++ b/middleware.js @@ -2,11 +2,13 @@ export const config = { matcher: [ /* * 匹配除以下路径之外的所有路径: - * - api routes (以 /api/ 开头) + * - 认证接口 /api/auth(登录/登出本身不能要求已登录) * - 静态文件 (以 . 结尾) * - 其他静态资源 + * 注意:/api 及其他 /api/* 路径必须经过认证检查, + * 否则 /api 会命中 SPA 兜底 rewrite 返回完整前端,造成未授权访问绕过 */ - '/((?!api|_next/static|_next/image|favicon.ico|assets/|.*\\.).*)' + '/((?!api/auth|_next/static|_next/image|favicon.ico|assets/|.*\\.).*)' ], };