Skip to content

Commit 1313265

Browse files
waleedlatif1claude
andcommitted
fix: treat Lua nil return as locked when OTP key is missing
When the Redis key is deleted/expired between getOTP and incrementOTPAttempts, the Lua script returns nil. Handle this as 'locked' instead of silently treating it as 'incremented'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2f85b31 commit 1313265

File tree

1 file changed

+2
-1
lines changed
  • apps/sim/app/api/chat/[identifier]/otp

1 file changed

+2
-1
lines changed

apps/sim/app/api/chat/[identifier]/otp/route.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ async function incrementOTPAttempts(
143143
}
144144
const key = `otp:${email}:${chatId}`
145145
const result = await redis.eval(ATOMIC_INCREMENT_SCRIPT, 1, key, MAX_OTP_ATTEMPTS)
146-
return result === 'LOCKED' ? 'locked' : 'incremented'
146+
if (result === null || result === 'LOCKED') return 'locked'
147+
return 'incremented'
147148
}
148149

149150
// DB path: optimistic locking with retry on conflict

0 commit comments

Comments
 (0)