From f189b292d06608ac4a7c6beceb0a46a18ffda6cd Mon Sep 17 00:00:00 2001 From: B SIMAK AHMED <1NZ24CS030@newhorizonindia.edu> Date: Mon, 23 Nov 2026 19:31:59 +0530 Subject: [PATCH] Fail closed when login lockout counter cannot be recorded --- src/lib/login.functions.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/lib/login.functions.ts b/src/lib/login.functions.ts index f32e34c..61a21cd 100644 --- a/src/lib/login.functions.ts +++ b/src/lib/login.functions.ts @@ -124,14 +124,9 @@ export const loginWithProtection = createServerFn({ method: "POST" }) }); if (authError || !authData.user || !authData.session) { - // Authentication failed regardless of whether lockout telemetry can be persisted. - // Never replace the user-facing credential error with an internal RPC failure. - let failureRow: LockoutRow | null = null; - try { - failureRow = await recordFailure(supabaseAdmin, lockoutKey); - } catch (error) { - console.error("[login] unable to persist failed-attempt lockout state", error); - } + // Count every failed credential pair (unknown email or wrong password) in + // the same per-IP counter. Fail closed if the counter cannot be persisted. + const failureRow = await recordFailure(supabaseAdmin, lockoutKey); const lockedUntil = failureRow?.locked_until ?? null; const locked = !!lockedUntil && new Date(lockedUntil).getTime() > Date.now();