Skip to content

fix(copilot): follow the credential's GitHub host on every quota rung - #1312

Closed
ozymandiashh wants to merge 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/1306-copilot-host-rungs
Closed

ozymandiashh wants to merge 3 commits into
getagentseal:mainfrom
ozymandiashh:fix/1306-copilot-host-rungs

Conversation

@ozymandiashh

@ozymandiashh ozymandiashh commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Every Copilot credential rung now carries its own GitHub host. [Feature Request] Support Copilot Enterprise on custom *.ghe.com hosts #1286 fixed
    hosts.json and apps.json; the rungs that carried none —
    COPILOT_GITHUB_TOKEN / GH_TOKEN / GITHUB_TOKEN, gh auth token, and a
    pasted token — were still sent to api.github.com, so a user whose only
    Copilot credential is a GitHub Enterprise Cloud login got a 401 and a
    terminal failure. The environment rung reads GH_HOST, the gh rung reads
    the host out of gh's own hosts.yml (GH_CONFIG_DIR, then
    XDG_CONFIG_HOME/gh, then ~/.config/gh, picked the way gh picks the host
    for gh auth token, with no second subprocess), and macOS Settings gains a
    GitHub host field beside the pasted token, saved in the same Keychain record
    so the token and the host can never drift apart.
  • Hardening carried forward from fix(menubar): follow the credential's GitHub host for Copilot quota #1305: GH_HOST, gh's hosts.yml keys and
    the pasted host are three new untrusted inputs, and each reaches the existing
    character validation untouched, so a crafted value such as
    evil.com?.ghe.com fails closed with no request rather than pointing the
    Authorization header at api.evil.com. Settings refuses an unaddressable
    host at the field instead of storing it, and the dormant connection row no
    longer promises api.github.com before anything has been fetched.
  • codeburn quota mirrors the environment and gh rungs so the CLI and the
    Windows Capacity Dock report what the menubar reports; its gh rung reads
    the token and the host out of one hosts.yml entry instead of spawning gh.
    The pasted rung stays macOS-only — it lives in that app's Keychain item.
    Behaviour change worth noting: a shell exporting GITHUB_TOKEN, or a gh
    login without Copilot, now reports a Copilot fetch failure where it used to
    report "disconnected", which is what the menubar has always reported for
    those credentials.
  • Adding a field to the shared provider credential record required a
    hand-written init(from:) using decodeIfPresent: Swift's synthesized
    decoder ignores property defaults and throws on a missing key, so every
    credential saved before the field — for every provider — would otherwise stop
    decoding. A test pins that.

Testing

  • I have tested this locally against real data (not just unit tests) — see
    the note below: this machine has a github.com Copilot credential only.
  • npm test passes
  • npm run build succeeds

cd mac && swift build passes. swift test cannot run on this machine (CLT
only, no Testing module — also true on pristine main), so the new pure
logic and all five rung resolutions were verified with a standalone swiftc
harness compiling the real sources and asserting exactly what the XCTest files
assert; each of seven mutations (dropping the host from any rung, dropping the
character guard, reading indented YAML keys as hosts, making host a required
decode key) was caught. npx tsc --noEmit is clean and npm test reports 3987
passing. Verified on this machine against a real github.com credential only —
there is no GitHub Enterprise Cloud account or enterprise gh login here, so
the *.ghe.com paths are unit-tested, as in #1305.

Closes #1306

…d gh rungs

getagentseal#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 getagentseal#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 getagentseal#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 getagentseal#1306
@iamtoruk

Copy link
Copy Markdown
Member

Landed as #1313 (4a316da) with your three commits and authorship intact, rebased onto current main, plus one commit dropping the CLI rung additions: #1306 was about the menubar's hostless rungs, and adding env and gh rungs to codeburn quota would turn an exported GITHUB_TOKEN or a Copilot-less gh login into a fetch failure where it said disconnected before. The macOS half is unchanged. Verified on this machine: winning rung is gh auth token, hosts.yml lists github.com only, resolved URL equals main, HTTP 200 with the expected keys; GH_HOST=acme.ghe.com resolves to api.acme.ghe.com, github.acme.net and evil.com?.ghe.com are refused with no request. 506 + 159 tests, mutation-proven. Thank you.

@iamtoruk iamtoruk closed this Sep 12, 2026
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.

Copilot quota: gh auth token, env var and pasted-token rungs always target api.github.com

2 participants