Repository navigation
fix(menubar): follow the credential's GitHub host on every quota rung - #1313
Merged
Merged
Conversation
…d gh rungs #1286 taught the credential files to carry the GitHub host their token came from, but the environment and `gh auth token` rungs carried none, so they were always addressed to api.github.com. A user whose only Copilot credential is a GitHub Enterprise Cloud login — GH_TOKEN exported alongside GH_HOST, or `gh auth login --hostname <tenant>.ghe.com` — got a 401 and a terminal failure with nothing to act on. The environment rung now reads GH_HOST out of the same environment as the token. The gh rung resolves the host from gh's own hosts.yml, found via GH_CONFIG_DIR, then XDG_CONFIG_HOME/gh, then ~/.config/gh, and picked the way gh picks the host for `gh auth token`: GH_HOST, else the single configured host, else dotcom. That is a file read rather than a second `gh auth status` spawn, because gh writes hosts.yml for every login, keyring-backed ones included. Both are new untrusted inputs, so they stay raw all the way to `apiHost(for:)`, where #1286's character validation refuses a crafted value such as `evil.com?.ghe.com` before any URL exists — that host passes the `.ghe.com` suffix check but builds a URL whose host is api.evil.com, which would then receive the Authorization header.
The last rung of the chain is a token the user pastes into Settings, and an enterprise personal access token pasted there was still sent to api.github.com. Settings now takes the host beside the token, defaulting to github.com, and saves both in the same provider Keychain record so the host a request is addressed to always comes from the entry that carried the token. A host no endpoint can be derived from is refused at the field instead of being stored and reported later as a terminal fetch failure, and the crafted values #1286 guarded against are refused there too. Clearing the token clears the host with it, so a stale tenant can never be paired with the next token. The record's decoding moves into an extension and reads every key with decodeIfPresent: Swift's synthesized init(from:) ignores a property's default and throws on a missing key, so adding a field would otherwise make every credential saved before it unreadable — for every provider, not just Copilot. The dormant connection row no longer promises api.github.com before anything has been fetched; it names a host only once one has answered. Tests cover the three new host sources with a hostile value each, the rung wiring for all five rungs, the gh hosts.yml key scan, and that a record written before the host field still decodes.
The CLI adapter read only the editor-plugin files, so `codeburn quota` and the Windows Capacity Dock — which has no Settings screen to fall back on — could not see an enterprise credential that lives anywhere else. It now walks the same rung order as the menubar for the sources a CLI can reach: the plugin files, then COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN paired with GH_HOST, then gh's own hosts.yml. The gh rung reads the oauth_token out of that file rather than spawning gh, so the token and the host come from one entry and a keyring-backed login simply has no token there and falls through. The pasted-token rung stays macOS-only: it lives in that app's Keychain item, which has no CLI equivalent. Note the behaviour change this implies: a shell that exports GITHUB_TOKEN, or a gh login with no Copilot entitlement, now reports a Copilot fetch failure where it previously reported "disconnected". That is the same answer the menubar has always given for those credentials. The existing suites pin env and ghConfigPaths explicitly so a developer's own GH_TOKEN or gh login can never change what they read. Closes #1306
Issue #1306 is about the macOS menubar's rungs. The CLI adapter gaining the environment and gh rungs is a behaviour change it did not ask for: a shell with GITHUB_TOKEN exported, or a gh login without Copilot, would start reporting a fetch failure where `codeburn quota` reported "disconnected". src/quota/copilot.ts and its suites go back to main untouched, including the hostname character check the endpoint helpers already had. CHANGELOG and docs drop the CLI claims.
This was referenced Sep 12, 2026
iamtoruk
added a commit
that referenced
this pull request
Sep 12, 2026
Rebase resolution for #1289 onto main (#1306, #1313, #1314, #1315, #1328, #1329). Conflicts kept both intents: main's second-row title composition, glance-window accessibility actions, cache-read line, host field and merged Notifications section keep their behaviour and now resolve through L(…). Adds 14 keys to both tables, drops 4 that no longer have a call site, and retranslates the two Copilot explanations main rewrote.
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.
Supersedes #1312 by @ozymandiashh. Same three commits rebased onto main, plus one commit that drops the CLI half.
Closes #1306.
What ships
The macOS menubar's Copilot rungs that carried no host:
GH_HOSTout of the same environment asCOPILOT_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKENhosts.yml(GH_CONFIG_DIR, thenXDG_CONFIG_HOME/gh, then~/.config/gh), picked the way gh'sDefaultHostpicks it:GH_HOST, else the single configured host, elsegithub.com. File read, not a second subprocess: gh writes that file for keyring logins too.github.com.CapacityDockProviderCredentialdecoding moves to a hand-writteninit(from:)withdecodeIfPresentso every record saved before the field still decodes, for all providers.api.github.com.Every new host source stays raw until
CopilotHostEndpoint.apiHost(for:), where #1286's character check refuses it.evil.com?.ghe.comand a GHES host likegithub.acme.netfail closed with no request instead of falling back to dotcom with an enterprise token.What was dropped
#1312's third commit also added the env and gh rungs to
src/quota/copilot.ts. #1306 did not ask for that, and it changes behaviour: a shell withGITHUB_TOKENexported, or a gh login without Copilot, would start reporting a Copilot fetch failure wherecodeburn quotareported "disconnected".20bde265putssrc/quota/copilot.tsand its three suites back to main byte for byte, hostname check included, and trims the CLI claims from CHANGELOG and docs.git diff main -- src/ tests/is empty.Checks
This machine, github.com only.
*.ghe.comis unit-tested, not exercised live.Rung state here: no
COPILOT_GITHUB_TOKEN/GH_TOKEN/GITHUB_TOKEN, noGH_HOST, no~/.config/github-copilot/*,~/.copilot/config.jsonpresent but carrying no token,~/.config/gh/hosts.ymllisting one host (github.com, keyring-backed, nooauth_tokenin the file). Winning rung is 4,gh auth token.The PR's resolver compiled standalone and run against that state:
Same URL main builds. Issuing it with the local gh token and the headers this code sends:
HTTP 200, body keys includecopilot_plan(individual) andquota_snapshots(chat,completions,premium_interactions).Builds and tests:
swift buildclean,swift test506 swift-testing in 59 suites + 159 XCTest, 0 failures,swift build -c releaseclean. Rootnpx tsc --noEmitclean,vitest tests/quota-copilot-*20/20,tests/quota-providers.test.ts17/17.Mutation check: making the env rung ignore
GH_HOSTfailstestEnvironmentTokenFollowsGHHostandtestHostileHostFromAnyNewSourceFailsClosedWithoutARequest(4 assertions).