fix(web): rate-limit and shorten lifetime of login OTP codes#1924
Open
richiemcilroy wants to merge 2 commits into
Open
fix(web): rate-limit and shorten lifetime of login OTP codes#1924richiemcilroy wants to merge 2 commits into
richiemcilroy wants to merge 2 commits into
Conversation
|
Paragon Review Skipped Hi @richiemcilroy! Your Polarity credit balance is insufficient to complete this review. Please visit https://app.paragon.run to finish your review. |
|
Superagent didn't find any vulnerabilities or security issues in this PR. |
Member
Author
|
@greptileai please review the PR |
Member
Author
|
@greptileai please review the PR |
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.
Shortens the email login OTP code validity to 15 minutes and adds per-email rate limiting on the verify and send endpoints, so the 6-digit code can no longer be brute-forced.
Greptile Summary
This PR hardens the email OTP login flow by shortening the verification-code lifetime from NextAuth's 24-hour default to 15 minutes, and wrapping the NextAuth catch-all route with per-email rate limiting backed by the Vercel Firewall, preventing both brute-force attacks and mailbombing.
packages/database/auth/auth-options.ts: addsmaxAge: 15 * 60toEmailProviderand corrects the dev-mode log message to match.apps/web/lib/rate-limit.ts: introduces a newisRateLimitedhelper (production-only, fail-open) that centralises@vercel/firewallusage;RATE_LIMIT_IDSpre-declares rule strings for several planned future endpoints in addition to the two used here.apps/web/app/api/auth/[...nextauth]/route.ts: wraps the handler withotpRateLimited, which gates/callback/emailand/signin/emailper-email (falling back to per-IP when the email is absent), usingreq.clone()to safely read the POST body without consuming the stream the NextAuth handler needs.Confidence Score: 5/5
Safe to merge — the changes are additive security hardening with a well-documented fail-open fallback, and no existing functionality is altered.
All three changed files make narrow, well-scoped changes: the OTP lifetime reduction is a one-liner with no side effects, the new rate-limit helper faithfully mirrors the existing @vercel/firewall pattern already in production, and the route wrapper correctly clones the request body before forwarding to NextAuth.
No files require special attention.
Important Files Changed
Reviews (3): Last reviewed commit: "fix(web): refine OTP rate-limit key hand..." | Re-trigger Greptile