fix(auth): return 4xx for bad OIDC authorization codes#1790
Conversation
AuthCallback returned a 500 (internal) whenever the OIDC token exchange failed with an oauth2 error like invalid_grant. That error means the authorization code was bad (expired, already used, or the redirect did not match) which is a client problem, not a server fault. It fired a critical alert for normal background noise such as retries, double submits, and link prefetching. Detect the oauth2.RetrieveError from the token exchange and wrap it in a new ErrOIDCTokenExchange sentinel. The handler maps that sentinel to CodeInvalidArgument so the caller gets a 4xx instead of a 500. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 31 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughOIDC token retrieval errors are classified using OAuth2 invalid-grant detection, wrapped with a public sentinel, tested, and returned by ChangesOIDC error handling
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/api/v1beta1connect/authenticate.go (1)
110-114: 🔒 Security & Privacy | 🟠 Major | ⚡ Quick winReturn a stable client-facing error here.
connect.NewErrorsendserr.Error()to clients, andFinishFlowwrapsErrOIDCTokenExchangewith the rawoauth2.RetrieveError. Log the original error, but returnauthenticate.ErrOIDCTokenExchange(or another fixed public error) instead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 79e07395-0971-4c8e-8e75-cd8c7597dec2
📒 Files selected for processing (2)
core/authenticate/service.gointernal/api/v1beta1connect/authenticate.go
Coverage Report for CI Build 29902145949Coverage decreased (-0.004%) to 46.22%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
oauth2 returns a RetrieveError for any non-2xx token endpoint response, so the earlier check also turned provider 429 and 5xx failures into a 4xx. That would hide a real IdP outage and stop it from paging. Narrow the check to RFC 6749 "invalid_grant" via a small isInvalidGrantErr helper, and add unit tests covering invalid_grant, 429, 5xx, misconfig, and non-oauth2 errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
A malformed (non-base64) state made ExtractFlowFromOIDCState fail, which FinishFlow turned into ErrUnsupportedMethod and the handler mapped to a 500. An empty or invalid state already returned a 400, so the same class of bad client input gave two different codes. Map ErrUnsupportedMethod to CodeInvalidArgument in AuthCallback so a bad state is a 4xx, consistent with the empty-state case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Live test resultsTested against a local build of this branch (commit
Before this PR, cases 1 and 4 returned
Not exercised liveA token-endpoint error that is a |
Problem
AuthCallbackreturns a500(internal) whenever the OIDC token exchange fails with an oauth2 error likeinvalid_grant:invalid_grantmeans the authorization code was bad. That is a client-side problem, not a server fault. It happens during normal operation:🤖 Generated with Claude Code