fix: prevent Git credential overwrite when authorizing a second account of the same provider [INS-3035] - #10316
Open
pavkout wants to merge 2 commits into
Open
fix: prevent Git credential overwrite when authorizing a second account of the same provider [INS-3035]#10316pavkout wants to merge 2 commits into
pavkout wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes an OAuth reauthorization edge case where authorizing a second account for the same Git provider could overwrite an existing credential. It does so by threading an explicit credentialId through the OAuth initiation → state cache → completion flow, so updates only happen when the user explicitly reauthorizes an existing credential; otherwise a new credential is always created.
Changes:
- Thread
credentialIdthrough the OAuth flow (UI → route action → main process → provider initiate/complete) to make update-vs-create explicit. - Update GitHub/GitLab OAuth state caches to carry the reauthorization
credentialIdand use it to deterministically select the credential to update. - Add unit tests for create-vs-update branching and invalid/stale state/id scenarios for both providers.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/insomnia/src/ui/components/settings/credentials.tsx | Passes the edited credential’s id when clicking Reauthorize so the flow can update the intended row. |
| packages/insomnia/src/sync/git/providers/types.ts | Extends the provider interface to allow initiateOAuth(credentialId?). |
| packages/insomnia/src/sync/git/providers/gitlab.ts | Stores { verifier, credentialId? } in the state cache and uses credentialId to update only the explicitly reauthorized credential. |
| packages/insomnia/src/sync/git/providers/github.ts | Stores state -> credentialId? and updates only the explicitly reauthorized credential (otherwise always creates). |
| packages/insomnia/src/sync/git/providers/tests/gitlab.test.ts | Adds unit coverage for GitLab OAuth create-vs-update branching and state/id edge cases. |
| packages/insomnia/src/sync/git/providers/tests/github.test.ts | Adds unit coverage for GitHub OAuth create-vs-update branching and state/id edge cases. |
| packages/insomnia/src/routes/git-credentials.init-sign-in.tsx | Extends the route action payload to forward credentialId from the renderer to the main process. |
| packages/insomnia/src/main/git-service.ts | Updates the main-process entrypoint to accept credentialId and pass it into initiateOAuth. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
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
Authorizing a second, different account for the same Git provider (e.g. a
second GitHub account) silently overwrote the first credential instead of
adding a new one, because
completeOAuthpicked an existing credential toupdate by guessing — matching on email, or falling back to "the only existing
credential for this provider" if there was exactly one.
credentialId, threaded throughthe OAuth flow (
initiateOAuth(credentialId)→ OAuth state cache →completeOAuth) so the update path only ever fires when the user explicitlyclicked Reauthorize on an existing credential.
credentials already exist for that provider or what email the new account
uses.
second distinct credential, reauthorize-by-id, stale/cross-provider id
fallback, invalid OAuth state).
Test plan
npm test -w packages/insomnia -- src/sync/git/providers/__tests__/github.test.ts src/sync/git/providers/__tests__/gitlab.test.ts— 12/12 passingnpm run linton changed files — cleantsc --noEmiton changed files — no errors