fix: return valid redirect url on auth rate-limit JSON response (#2267) - #3361
Open
yachikadev wants to merge 3 commits into
Open
fix: return valid redirect url on auth rate-limit JSON response (#2267)#3361yachikadev wants to merge 3 commits into
yachikadev wants to merge 3 commits into
Conversation
…anshu-byte-coder#2267) Prevents raw JSON from surfacing to the user when an interrupted OAuth flow triggers next-auth's client-side signIn({redirect:false}) fetch path. Also relaxes AUTH_LIMIT from 5 to 8 to give legitimate interrupted-retry attempts more headroom.
GSSoC Label Checklist 🏷️@Priyanshu-byte-coder — please apply the appropriate labels before merging: Difficulty (pick one):
Quality (optional):
Validation (required to score):
|
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
Fixes the GitHub sign-in flow showing a raw JSON error instead of a friendly message when the auth rate limiter is triggered by an interrupted-then-retried sign-in attempt (e.g. hitting Back mid-authorization and clicking "Sign in with GitHub" again).
closes #2267
Root Cause
src/middleware.tshandles auth rate-limit hits differently depending on the request type:Accept: text/html) → redirects gracefully to/auth/signin?error=...urlfieldThe GitHub sign-in button calls
signIn("github", { redirect: false }), which always goes through the fetch path. NextAuth's client-side handler expects every response to include aurlfield — without it, parsing silently breaks and the raw JSON leaks straight to the screen instead of becoming a toast.Changes
src/middleware.tsRate-limit JSON responses now always include a valid
url(pointing to/auth/signin?error=RateLimitError) and use theRateLimitErrorcode, which maps correctly to the existing message inAUTH_ERROR_MESSAGES.src/lib/auth-rate-limit.tsAUTH_LIMITincreased from5to8requests per 15-minute window — enough headroom for a legitimate interrupted-retry attempt, without weakening brute-force protection.Before → After
signIn({redirect:false})Notes
src/middleware.ts,src/lib/auth-rate-limit.ts) to directly match the issue's repro steps.src/app/auth/signin/page.tsxneeded no changes — its existingtry/catch+toast.errorhandling now works correctly once the response shape is fixed upstream.