Skip to content

fix: return valid redirect url on auth rate-limit JSON response (#2267) - #3361

Open
yachikadev wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
yachikadev:fix/2267-oauth-interrupted-flow-rate-limit
Open

fix: return valid redirect url on auth rate-limit JSON response (#2267)#3361
yachikadev wants to merge 4 commits into
Priyanshu-byte-coder:mainfrom
yachikadev:fix/2267-oauth-interrupted-flow-rate-limit

Conversation

@yachikadev

Copy link
Copy Markdown
Contributor

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.ts handles auth rate-limit hits differently depending on the request type:

  • Full page navigation (Accept: text/html) → redirects gracefully to /auth/signin?error=...
  • Fetch/XHR request → returns a bare JSON body with no url field

The 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 a url field — without it, parsing silently breaks and the raw JSON leaks straight to the screen instead of becoming a toast.

Changes

  • src/middleware.ts
    Rate-limit JSON responses now always include a valid url (pointing to /auth/signin?error=RateLimitError) and use the RateLimitError code, which maps correctly to the existing message in AUTH_ERROR_MESSAGES.
  • src/lib/auth-rate-limit.ts
    AUTH_LIMIT increased from 5 to 8 requests per 15-minute window — enough headroom for a legitimate interrupted-retry attempt, without weakening brute-force protection.

Before → After

Scenario Before After
Rate limit hit via full page load Graceful redirect ✅ Graceful redirect ✅
Rate limit hit via signIn({redirect:false}) Raw JSON on screen ❌ Friendly toast ✅

Notes

  • Scoped entirely to the auth rate-limiting path (src/middleware.ts, src/lib/auth-rate-limit.ts) to directly match the issue's repro steps.
  • src/app/auth/signin/page.tsx needed no changes — its existing try/catch + toast.error handling now works correctly once the response shape is fixed upstream.

…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.
@github-actions github-actions Bot added type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) gssoc26 GSSoC 2026 contribution type:security GSSoC type bonus: security (+20 pts) labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown

GSSoC Label Checklist 🏷️

@Priyanshu-byte-coder — please apply the appropriate labels before merging:

Difficulty (pick one):

  • level:beginner — 20 pts
  • level:intermediate — 35 pts
  • level:advanced — 55 pts
  • level:critical — 80 pts

Quality (optional):

  • quality:clean — ×1.2 multiplier
  • quality:exceptional — ×1.5 multiplier

Validation (required to score):

  • gssoc:approved — counts for points
  • gssoc:invalid / gssoc:spam / gssoc:ai-slop — does not score

Type labels (type:*) are auto-detected from files and title. Review and adjust if needed.
Points formula: (difficulty × quality_multiplier) + type_bonus

@github-actions github-actions Bot added the type:testing GSSoC type bonus: tests (+10 pts) label Aug 4, 2026
@yachikadev

Copy link
Copy Markdown
Contributor Author

Hi @Priyanshu-byte-coder , just following up on this PR — it's been open for a while now. Could you review it when you have a moment? Happy to make any changes you'd suggest, or if it's good to go, would appreciate the merge. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc26 GSSoC 2026 contribution type:bug GSSoC type bonus: bug fix type:feature GSSoC type bonus: new feature type:performance GSSoC type bonus: performance (+15 pts) type:security GSSoC type bonus: security (+20 pts) type:testing GSSoC type bonus: tests (+10 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] : "Too many authentication attempts" error when interrupting OAuth flow

1 participant