Validate login redirects for actual Next.js data routes
waterfall-wiki CI and deployment / verify-and-deploy (push) Failing after 16m15s

This commit is contained in:
2026-10-27 01:18:04 +08:00
parent 86d7f5adf9
commit 01c0f6ca73
3 changed files with 17 additions and 5 deletions
+5
View File
@@ -56,3 +56,8 @@ export function sessionCookie(token: string, clear = false) {
return `${SESSION_COOKIE}=${token}; Path=/; HttpOnly; SameSite=Lax; Max-Age=${clear ? 0 : SESSION_SECONDS}${process.env.AUTH_COOKIE_SECURE === 'false' ? '' : '; Secure'}`;
}
export function safeReturn(value: unknown) { return typeof value === 'string' && value.startsWith('/') && !value.startsWith('//') && !/[\\\r\n]/.test(value) && !value.startsWith('/login') ? value : '/'; }
export function isLoginRedirect(value: string | null, base: string) {
if (!value) return false;
try { const target = new URL(value,base); return target.origin === new URL(base).origin && (target.pathname === '/login' || /^\/_next\/data\/[^/]+\/login\.json$/.test(target.pathname)); } catch { return false; }
}