Skip to content

Commit 44b8aba

Browse files
waleedlatif1claude
andcommitted
fix: check attempt count before OTP comparison to prevent bypass
Reject OTPs that have already reached max failed attempts before comparing the code, closing a race window where a correct guess could bypass brute-force protection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 16072b5 commit 44b8aba

File tree

1 file changed

+9
-0
lines changed
  • apps/sim/app/api/chat/[identifier]/otp

1 file changed

+9
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,15 @@ export async function PUT(
311311

312312
const { otp: storedOTP, attempts } = decodeOTPValue(storedValue)
313313

314+
if (attempts >= MAX_OTP_ATTEMPTS) {
315+
await deleteOTP(email, deployment.id)
316+
logger.warn(`[${requestId}] OTP already locked out for ${email}`)
317+
return addCorsHeaders(
318+
createErrorResponse('Too many failed attempts. Please request a new code.', 429),
319+
request
320+
)
321+
}
322+
314323
if (storedOTP !== otp) {
315324
const result = await incrementOTPAttempts(email, deployment.id, storedValue)
316325
if (result === 'locked') {

0 commit comments

Comments
 (0)