Repository navigation
fix(menubar): follow the credential's GitHub host for Copilot quota - #1305
Merged
Merged
Conversation
Both Copilot quota readers hardcoded https://api.github.com/copilot_internal/user and dropped the host their credential was read from, so an enterprise on a GitHub Enterprise Cloud data-residency host (<tenant>.ghe.com) could only ever report "Temporarily unavailable": its token is not a dotcom token, and dotcom is not an endpoint it may be sent to. A discovered credential now carries its host. hosts.json is keyed by GitHub host and newer apps.json files key by "<host>:<app id>", so the token and the host always come from the same entry; the rungs that carry no host of their own (an app-name apps.json key, COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN, gh auth token, a pasted token) mean dotcom. The endpoint follows the host: api.github.com for github.com, and api.<tenant>.ghe.com for an Enterprise Cloud host. With several hosts signed in github.com wins, otherwise the first .ghe.com tenant in sorted order, which keeps the pick stable across reads; with exactly one, that host is used. A host neither rule can address, such as a self-hosted GitHub Enterprise Server install, fails with a message naming that host instead of falling back to dotcom, and network and HTTP failures name the host that was tried. macOS Settings now says which host answered in the Copilot connection row. Tokens are still never logged and sanitizeForUI is unchanged. Closes #1286
The fake credential reader keyed its files by splitting the path on "/", but the adapter builds the path with path.join, which uses a backslash on Windows: every lookup missed there, so the credential read as absent and the six adapter-level cases saw no request and a "disconnected" quota. path.basename is separator-correct on both platforms. Test-only; the reader itself is unchanged and the existing Windows path test still covers the real directories.
The `.ghe.com` suffix check ran on a normalized string that still allowed `?`, `#`, `\` and spaces, and that string was interpolated straight into the request URL. `evil.com?.ghe.com` in a hosts.json key passes the suffix check but builds a URL whose host is `api.evil.com`, so the Authorization header lands on a host that was never approved. Verified on macOS: URL(string:) parses it as host `api.evil.com`, path `/`. Both readers now require the normalized host to look like a DNS name before an endpoint is derived; anything else fails as an unsupported host, with no request sent.
iamtoruk
force-pushed
the
fix/copilot-host-followups
branch
from
September 12, 2026 13:14
fa1d3f1 to
0225088
Compare
3 tasks done
This was referenced Sep 12, 2026
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 #1291 by @ozymandiashh: the same commits rebased onto current main, plus one hardening commit.
swift test 459 + 145 XCTest pass; npm test 3969 pass.