fix(auth): rate-limit failed login attempts per identity - #1304
Merged
RUKAYAT-CODER merged 1 commit intoAug 30, 2026
Conversation
Add per-identity (email) sliding-window rate limiting to prevent credential-stuffing attacks that rotate IPs but target the same account. - Add LOGIN_IDENTITY tier (5 attempts / 15 min) in ratelimit.ts - Add checkIdentityRateLimit() and resetIdentityRateLimit() functions - Add checkLoginRateLimit() and resetLoginRateLimit() helpers in authMiddleware.ts - Wire into login route: block on identity limit, reset on successful login - Add 6 unit tests covering limit, block, reset, independence, and expiry Closes rinafcode#1153 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@anifast-123 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Thank you for contributing to the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds per-identity (email) sliding-window rate limiting to prevent credential-stuffing attacks that rotate IPs but target the same account.
Changes
src/lib/ratelimit.ts: AddedLOGIN_IDENTITYtier (5 attempts / 15 min window),checkIdentityRateLimit()andresetIdentityRateLimit()functions that track failed attempts per email using aidentity:key prefixsrc/lib/authMiddleware.ts: AddedcheckLoginRateLimit(email)andresetLoginRateLimit(email)helpers that wrap the identity rate limitersrc/app/api/auth/login/route.ts: Wired in per-identity checks — blocks when limit exceeded, increments counter on failed attempt, resets on successful loginsrc/app/api/tutorials/__tests__/ratelimit.test.ts: Added 6 tests covering limit enforcement, blocking, reset after success, independence across identities, remaining count, and window expiryHow It Works
checkLoginRateLimit(email)checks if the email has exceeded 5 failed attempts in the last 15 minutes. If so, returns 429 immediately.resetLoginRateLimit(email)clears the counter so the next batch of attempts starts fresh.AUTHtier, providing defense-in-depth against credential-stuffing bots that rotate IPs.Testing
Closes #1153