fix(auth): apply authLimiter to OTP and password-reset endpoints#257
fix(auth): apply authLimiter to OTP and password-reset endpoints#257anshul23102 wants to merge 2 commits into
Conversation
send-otp, verify-otp, forgot-password, and reset-password fell under router.use(dashboardLimiter) — 1000 requests per 15 minutes — because they were defined after that middleware call. authLimiter (10 req/15 min) was only applied to /login and /register. An attacker could: - Brute-force POST /verify-otp at 1000 attempts per 15 minutes - Flood POST /send-otp to exhaust OTP email budget - Iterate POST /forgot-password to enumerate registered accounts Fix: move the four endpoints before router.use(dashboardLimiter) and apply authLimiter explicitly to each. They are now capped at 10 requests per 15 minutes per IP, matching the login and register endpoints. Closes geturbackend#246
|
Warning Review limit reached
More reviews will be available in 56 minutes and 57 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Pull Request Description
Fixes #246
apps/dashboard-api/src/routes/auth.jsappliesauthLimiter(10 req/15 min) toPOST /loginandPOST /registeronly. All four OTP and password-reset routes (/send-otp,/verify-otp,/forgot-password,/reset-password) were defined afterrouter.use(dashboardLimiter)and inherited the 1000 req/15 min bucket instead.An attacker could:
POST /verify-otpat 1000 attempts per 15 minutes (6-digit OTP = 1,000,000 combinations; at this rate exhausted in ~250 hours, or parallelized across IPs)POST /send-otpto spam a target's email inbox at high volumePOST /forgot-passwordto enumerate registered email addressesRoot Cause
The four routes were placed after
router.use(dashboardLimiter)in the file, so Express applieddashboardLimiterto them before any route-level middleware.authLimiterwas never referenced on those routes.Solution
Move the four credential-adjacent routes before
router.use(dashboardLimiter)and attachauthLimiterexplicitly to each. They now share the same 10 req/15 min cap as/loginand/register. Routes that legitimately need the higherdashboardLimiterthreshold (/change-password,/delete-account,/refresh-token, etc.) remain unchanged.Changes Made
apps/dashboard-api/src/routes/auth.js
POST /send-otp,POST /verify-otp,POST /forgot-password, andPOST /reset-passwordabove therouter.use(dashboardLimiter)call.authLimiteras an explicit middleware argument on each of those four routes.router.use(dashboardLimiter).Type of Change
Testing & Validation
Backend Verification
POST /send-otpPOST /verify-otpPOST /forgot-passwordPOST /reset-passwordPOST /loginPOST /registerPOST /send-otp— 11th request received 429 Too Many Requests.POST /change-passwordand other dashboard-limiter routes unaffected.Screenshots / Recordings
Not applicable. This is a server-side rate limiting fix.
Checklist
GSSoC Label Request
Maintainer, could you please add the appropriate GSSoC label to this PR? This helps with contribution tracking and scoring under GSSoC '26. Thank you.
Built with for urBackend.