Repository navigation
Description
Description
When an isolated GH_CONFIG_DIR uses --insecure-storage, gh auth refresh writes the refreshed credential to that profile's hosts.yml. However, gh auth token --user <login> can return an older credential for the same login from the global OS keyring instead. Calling gh auth token without --user returns the freshly refreshed active credential.
This makes a successful scope refresh appear ineffective to callers that retrieve the token by username. In my case, only the active token had the newly requested codespace scope.
Steps to reproduce
-
Have an existing secure keyring credential for a GitHub login.
-
Create an isolated
GH_CONFIG_DIRfor the same login and authenticate it with--insecure-storage. -
With that login active in the isolated profile, run:
gh auth refresh --hostname github.com --scopes codespace --insecure-storage -
Clear
GH_TOKENandGITHUB_TOKEN, then retrieve both credentials:gh auth token --hostname github.com gh auth token --hostname github.com --user <login>
-
Compare hashes rather than printing the tokens, and inspect each token's scopes using
gh api --include /userwith the token supplied throughGH_TOKEN.
Actual behavior
- The two token hashes differ.
- The token returned without
--useris the refreshed token and includescodespace. - The token returned with
--useris the stale keyring token and does not includecodespace. - Both credentials belong to the same GitHub login.
Expected behavior
gh auth token --user <login> should return the credential just written for that login in the selected GH_CONFIG_DIR. An older global keyring entry should not shadow an explicitly selected profile's newer --insecure-storage credential.
Suspected cause
AuthConfig.Login(..., secureStorage=false) writes the per-user token under hosts.<host>.users.<login>.oauth_token but does not remove an existing keyring entry for that login. AuthConfig.TokenForUser checks the keyring before the profile config, so gh auth token --user returns the stale keyring value. By contrast, active-token resolution checks the profile config first.
The same precedence remains in current trunk. This is related to #12885, but that issue describes unqualified active-token lookup across multiple GH_CONFIG_DIR profiles rather than a refreshed profile token being shadowed during explicit --user lookup.
Environment
- GitHub CLI:
2.74.2 - OS: Windows
- Credential setup: global Windows Credential Manager entry plus isolated
GH_CONFIG_DIRusing--insecure-storage
Activity
cli-triage commentedon Sep 2, 2026
Caution
agentic threat detected
Threat detection flagged this output in warn mode. Manual review is REQUIRED before any follow-up automation.
Details
Potential security threats were detected in the agent output.
Review the workflow run logs for details.
Thanks for the detailed report and root-cause analysis. I'm suggesting
bugsince this is a clear, reproducible issue withgh auth token --userreturning a stale keyring credential instead of the refreshed--insecure-storagetoken for the same login, andpriority-3since it's a fairly narrow scenario (isolatedGH_CONFIG_DIR+--insecure-storage+ explicit--userlookup) with a workaround (retrieving the active token without--user). This looks related to but distinct from #12885 (which is about keychain lookups ignoring the account field for multi-account setups) rather than a duplicate.boyam01 commentedon Sep 3, 2026
@cli/code-reviewers, I'd like to work on this if the scope is welcome.
I traced the current lookup path on trunk at
adda317c11b892da5e5ed3fbbf26b69a5c163cc6. An insecure refresh stores the per-user token in the selectedGH_CONFIG_DIR, while normal explicit-user lookup checks the global keyring first. I would avoid deleting the keyring entry because it may still be authoritative for another config profile.Proposed acceptance criteria:
gh auth token --user <login>returns the selected profile credential.--secure-storage --user <login>remains keyring-only.--user, including environment-token precedence, remains unchanged.--secure-storagecontrols.TokenForUseris also used bygh auth statusfor inactive accounts. Should the selected-profile precedence apply to both consumers through that shared method, or only togh auth token --user?Could you confirm the intended contract or add
help wantedif this is suitable for an external contribution? I will not open a PR before that gate is satisfied.AI assistance disclosure: I used AI tooling to inspect the current code path and draft this proposed scope. I will review and stand behind any implementation, tests, and follow-up before submission.