fix(web): reject OAuth account-linking without a signed-in session#1221
fix(web): reject OAuth account-linking without a signed-in session#1221msukkari wants to merge 5 commits into
Conversation
If a user clicks "Connect Bitbucket" and their session-token cookie is missing or expired by the time the BB redirect arrives at our callback, @auth/core silently falls through to createUser and mints a new orphan User row from the OAuth profile. The orphan has no email, no UserToOrg, and the user's session cookie gets rebound to it, leaving them on a "request access" page. Add a signIn callback that calls auth() and refuses the request when the provider's purpose is account_linking and no session is present. SSO providers and credentials login are unaffected. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR adds session validation to the NextAuth configuration to block OAuth/OIDC account-linking attempts when no authenticated user session exists. A ChangesOAuth Account-Linking Session Validation
Sequence DiagramsequenceDiagram
participant Client
participant NextAuth
participant ProviderRegistry
participant AuthResolver
Client->>NextAuth: OAuth/OIDC provider callback (account)
NextAuth->>ProviderRegistry: getProviders() -> find provider for account.provider
NextAuth->>AuthResolver: auth() to resolve current session (if provider.purpose == "account_linking")
AuthResolver-->>NextAuth: session or null
NextAuth-->>Client: allow or deny sign-in (deny if account_linking && session == null)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
The fix is gated behind the sso entitlement (no OAuth identity providers are loaded in OSS deployments), so the [EE] prefix is appropriate per CLAUDE.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
OAuth providers configured with `purpose: "account_linking"` should only ever attach an identity to an existing signed-in user, never mint a new Sourcebot user. `@auth/core` does not know about this distinction and falls back to `createUser` when its session lookup returns null, which can happen when the user's session cookie expires while they are on the upstream consent screen. The result is a silent orphan `User` row and a confused user.
Add a `signIn` callback that refuses the request in that case.
Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation