Skip to content

fix(menubar): follow the credential's GitHub host for Copilot quota - #1305

Merged
iamtoruk merged 3 commits into
mainfrom
fix/copilot-host-followups
Sep 12, 2026
Merged

iamtoruk merged 3 commits into
mainfrom
fix/copilot-host-followups

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Supersedes #1291 by @ozymandiashh: the same commits rebased onto current main, plus one hardening commit.

  • Copilot quota requests follow the host the credential came from: github.com stays api.github.com, a .ghe.com entry in hosts.json or apps.json is queried at api..ghe.com, any other host fails closed with unsupportedHost and no request.
  • Hardening: the normalized host is character-validated before URL construction; a crafted hosts.json key containing ?, #, or percent-escapes could otherwise pass the .ghe.com suffix check and land on a different host. Same guard mirrored in src/quota/copilot.ts. Rejection routes into the existing unsupported-host path.
  • Interaction with fix(mac): preserve explicit Copilot disconnect #1278: the explicit-disconnect gate runs before any request is built, so a host change cannot resurrect a disconnected provider. The 8 disconnect tests pass.
  • Verified on this machine (github.com only): the winning rung is gh auth token with no host, resolving to the same URL main builds, HTTP 200 with the expected copilot_plan and quota_snapshots keys. URLSession drops Authorization on a cross-host redirect, measured with a local probe.
  • Not verified end to end: the ghe.com path, there is no enterprise account here. Unit tests cover it.
  • Known limitation, unchanged from main and documented: the env-var, gh auth token and pasted-token rungs carry no host and always target api.github.com. Follow-up filed.

swift test 459 + 145 XCTest pass; npm test 3969 pass.

ozymandiashh and others added 3 commits September 12, 2026 05:56
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
iamtoruk force-pushed the fix/copilot-host-followups branch from fa1d3f1 to 0225088 Compare September 12, 2026 13:14
@iamtoruk
iamtoruk merged commit ef86348 into main Sep 12, 2026
27 of 28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants