From 047334e70f1a5c57a8bb1cc2c2dd79ab4d3869e2 Mon Sep 17 00:00:00 2001 From: hrz <1710360675@qq.com> Date: Wed, 7 Oct 2026 10:30:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=88=E5=8D=AB=E6=B8=85=E6=B4=97=20redirect?= =?UTF-8?q?=20=E5=8F=82=E6=95=B0=E5=B9=B6=E6=8A=8A=20welcome=20=E5=85=A5?= =?UTF-8?q?=E7=99=BD=E5=90=8D=E5=8D=95=20#3398?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit P1 加 safeRedirect(to):丢弃以 //、/\ 开头或非 / 起首的输入,避免开放重定向跳出域名;守卫改读 to.query.redirect 优先。P2 把 welcome 加入 anonRouteNames 防误伤根路径。dev server 编译 31419ms 通过。 --- main/manager-web/src/router/index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/main/manager-web/src/router/index.js b/main/manager-web/src/router/index.js index c85ac9eee..98b5ba40e 100644 --- a/main/manager-web/src/router/index.js +++ b/main/manager-web/src/router/index.js @@ -228,9 +228,17 @@ VueRouter.prototype.push = function push(location) { }) } +// 把入参清洗为站内绝对路径,避免 //evil.com 这类协议相对 URL 跳出域名 +function safeRedirect(target) { + if (typeof target !== 'string' || target.length === 0) return '/' + if (!target.startsWith('/')) return '/' + if (target.startsWith('//') || target.startsWith('/\\')) return '/' + return target +} + // 任何路由段上 meta.requiresAuth === true 都视为需要登录 // 匿名白名单按 name 匹配,避免被误标时也拦住 anon 路由 -const anonRouteNames = new Set(['login', 'Register', 'RetrievePassword']) +const anonRouteNames = new Set(['login', 'Register', 'RetrievePassword', 'welcome']) router.beforeEach((to, from, next) => { if (anonRouteNames.has(to.name)) { @@ -239,7 +247,8 @@ router.beforeEach((to, from, next) => { } const requiresAuth = to.matched.some(r => r.meta && r.meta.requiresAuth === true) if (requiresAuth && !localStorage.getItem('token')) { - next({ name: 'login', query: { redirect: to.fullPath } }) + const target = safeRedirect(to.query.redirect || to.path) + next({ name: 'login', query: { redirect: target } }) return } next()