feat: add rate limiting to auth routes via dedicated rateLimiter midd…#246
Merged
BHUVANSH855 merged 1 commit intoJun 23, 2026
Merged
Conversation
|
Someone is attempting to deploy a commit to the Bhuvansh's projects Team on Vercel. A member of the Team first needs to authorize it. |
BHUVANSH855
approved these changes
Jun 23, 2026
BHUVANSH855
left a comment
Member
There was a problem hiding this comment.
LGTM, thanks for adding this.
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.
📋 Pull Request — Add Rate Limiting to Auth Routes
🔗 Related Issue
Closes #235 — Add rate limiting to auth routes (login, signup, refresh-token) to prevent brute-force attacks
📝 Summary
The auth routes (
/login,/signup,/verify-signup,/forgot-password,/reset-password,/refresh-token) had no rate limiting applied, making them vulnerable to brute-force attacks and spam. This PR adds a dedicatedmiddleware/rateLimiter.jsfile with route-specific limiters and applies them to all sensitive auth endpoints.🐛 Root Cause
/login— attacker could send unlimited password guessesloginLimiter(10 req/15min)/signup— spam/fake account creation possiblesignupLimiter(20 req/15min)/forgot-passwordand/reset-password— OTP spam possibleforgotPasswordLimiter(5 req/15min)/refresh-token— token abuse possiblerefreshTokenLimiter(30 req/15min)✅ Changes Made
New Files
middleware/rateLimiter.jsloginLimiter,signupLimiter,refreshTokenLimiter,forgotPasswordLimiterModified Files
routes/authRoutes.jsmiddleware/rateLimiter.jsand applied to/login,/signup,/verify-signup,/forgot-password,/reset-password,/refresh-token🛡️ Rate Limit Configuration
POST /loginloginLimiterPOST /signupsignupLimiterPOST /verify-signupsignupLimiterPOST /forgot-passwordforgotPasswordLimiterPOST /reset-passwordforgotPasswordLimiterPOST /refresh-tokenrefreshTokenLimiter🧪 Testing Checklist
POST /login— returns429after 10 requests within 15 minutesPOST /signup— returns429after 20 requests within 15 minutesPOST /forgot-password— returns429after 5 requests within 15 minutesPOST /refresh-token— returns429after 30 requests within 15 minutessuccess: falseand descriptive messageRateLimit-*headers visible in response (standardHeaders: true)💻 How to Test Locally
📌 Coding Standards Followed
middleware/rateLimiter.js— separation of concerns, reusable across other route filesstandardHeaders: true— exposesRateLimit-*headers per RFC standardlegacyHeaders: false— disables deprecatedX-RateLimit-*headers