fix(auth): expire login OTP codes after the advertised 10 minutes - #2068
Merged
Conversation
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
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.
The email provider had no
maxAge, so next-auth applied its 24 hour default to login codes. The code is 6 digits (900k values), the verify path has no attempt limiting,proxy.tsexcludes/api/auth/*from middleware, and the only throttle is a 30 second client-side cooldown that is bypassed by calling the callback URL directly. A day-long window against that keyspace is a practical brute-force target.The OTP email already tells users "This code will expire in 10 minutes" and the dev console prints the same, so this makes the implementation match the contract users are already given. No user-visible change, 144x smaller window.
Also derives the dev console message from the constant so the two cannot drift again, and adds a test pinning
maxAge, since the failure mode here is silent: remove the line and next-auth quietly returns to 24 hours.Validated: the new test fails when the
maxAgeline is removed and passes with it, auth-options suite 3/3, typecheck and Biome clean.Follow-up worth tracking separately: shortening the window reduces exposure but does not close brute force. The durable fix is an attempt counter in
useVerificationToken(works for self-hosted too) or Vercel Firewall rules for theAUTH_OTP_VERIFYandAUTH_OTP_SENDids that already exist unused inlib/rate-limit.ts.Greptile Summary
The PR aligns login OTP expiration with the advertised ten-minute lifetime.
maxAgeto the NextAuth email provider.Confidence Score: 5/5
The PR appears safe to merge, with the implementation and regression test consistently enforcing the advertised ten-minute OTP lifetime.
The email provider now receives an explicit 600-second maximum age, the development message derives from the same constant, and the focused test pins the provider configuration without introducing a blocking failure.
Important Files Changed
Reviews (1): Last reviewed commit: "fix(auth): expire login OTP codes after ..." | Re-trigger Greptile