Repository navigation
-u is a login of the PR URL's host for the review run, --check and gc (fixes #29) - #32
Conversation
As show and rounds since #28: use_gh_user looks the login up on the PR URL's host (url_api_host), and every gh call of the run (the PR reads, the history, the account's login, the post, --check --json) and git's credential helper use its token for that host. A bare PR number stays a github.com login. pr.json keeps the login as given. tests/flow.sh: the stub gh logs each call's host and the token gh reads for it. -u alice on a PR at GHE.example.com:443: posted, every call with alice's token there; --check --json the same; a github.com PR (control): alice's github.com token; -u ci, a github.com login only: exit 1 before any other gh call, clone or model call, naming the host; a local-clone round on ghe.local: alice's token there, pr.json's user alice.
gc reads each PR's state with pr.json's login (or -u's, or GH_PR_REVIEW_USER) looked up on the PR's host, the <host> of its state folder, and that host's token. A github.com PR: unchanged. A pr.json an earlier version wrote for a PR on another host may hold a github.com login: when gh has no such login on that host, the PR is skipped with "could not read its state: no gh login for '<login>' on <host> — see: gh auth status" (use_gh_user's line only, not gh's own before it), as any PR whose state can't be read: the others are still done, exit 1. tests/gc.sh: the stub gh knows logins per host and logs the token gh reads for the --repo host. A GHE PR with alice: read with alice's GHE token, removed; a github.com PR (control): alice's github.com token, kept; bob, a login gh has on github.com but not on the GHE host: skipped, host and login named, its state not read, exit 1; -u alice: each PR with alice's token on its host.
With -u on a GHE.com PR (*.ghe.com) the account's token is in GH_TOKEN, which gh reads for github.com too: the preflight's gh auth status -h github.com checked it with github.com, which refuses it, and the run stopped there. The preflight now checks gh's login on the PR URL's host (github.com for a bare number, or --doctor alone); a failure names the host and the gh auth login --hostname that fixes it. tests/flow.sh: the stub's gh auth status checks the token gh reads for the host with that host. -u alice on acme.ghe.com: posted, every call (the preflight's too) with alice's acme.ghe.com token; -u alice on a GHE PR: the preflight checks ghe.example.com with her token there; a token the PR's host refuses: exit 1 at the preflight, the host named.
catalan-adobe
left a comment
There was a problem hiding this comment.
Approach
What it does: Review runs, --check, and gc now look up -u on the PR’s host. The startup check uses that host too. Bare PR numbers keep their github.com behavior.
Fit with the repo: This changes two callers, not the authentication mechanism. gh-pr-review uses the same lib/common.sh helpers as show and rounds; lib/gc.sh gets the host from the existing state-folder path. Base README.md documented different -u behavior for these commands. Issue #29 explains why review and cleanup were deferred together: one writes the login to pr.json, and the other reads it.
Strongest case for the approach as built: “The account shown was not the one that posted.” Selecting the account once in the CLI makes the check and the post agree for dashboard and command-line users alike.
Alternatives: Keep it as built. If an older saved login is absent on the Enterprise host, gc skips that PR, reports why, and continues. I’d version pr.json only if old records needed to preserve their former account behavior; that would mean maintaining two lookup rules.
Questions for the author: None.
Missing context: None.
Approach: Sound
Strengths
gh-pr-review:229selects the account before preflight, PR reads, or posting.tests/flow.sh:389–405checks the effective host and token on both the POST and--check --json, rather than treating a successful exit as proof that the right account was used.lib/gc.sh:611–619keeps each PR’s credentials in a subshell. A failed lookup skips that PR and sets the batch exit status without changing the credentials used for the next one.tests/gc.sh:1200–1213checks this across two hosts.
Issues
🚨 Critical (Must Fix Before Merge)
- [gh-pr-review:229] — The selected Enterprise token can be sent to a different Git host.
use_gh_userexportsGH_ENTERPRISE_TOKEN(lib/common.sh:77), but the Git credential helper is registered for every HTTPS host (gh-pr-review:641). If a user’s GitinsteadOfrule routes a clone through a separately authenticated HTTPS mirror, Git asks for the mirror’s credentials. Realgh auth git-credentialusesGH_ENTERPRISE_TOKENfor that host too, so the mirror receives the PR host’s token. Before this change, a stored Enterprise login was looked up by host rather than exported by-u.- Suggested fix: Keep the empty default credential helper, but register the
ghhelper only for the PR’s HTTPS host. Add an offline credential test that checks both destinations: the PR host gets the fixture token; an unrelated mirror does not.
- Suggested fix: Keep the empty default credential helper, but register the
⚠️ Important (Should Fix)
- [gh-pr-review:391] —
gh auth status -hchecks the host’s account inventory, not just the credential the review will use. With valid-u aliceand an expired stored token for Bob on the same Enterprise host, realghexits 1 and the review tells Alice to log in again. There is a second false negative without-u: with a valid Enterprise environment token but no stored entry or matchingGH_HOST,auth statusrejects the host before testing the token. The stub attests/flow.sh:110models neither behavior.- Suggested fix: Probe the effective credential directly with
gh api --hostname "$gh_host" user, preserving the host-specific error message. The returned login can serve the lateroperator_logincheck. Add cases for a stale unrelated account and an environment-only credential.
- Suggested fix: Probe the effective credential directly with
💡 Minor (Nice to Have)
-
[lib/gc.sh:614] — Selecting only the
no gh loginline discards the underlying error even when it is not a duplicate. For example, ifgh auth tokencannot parse its configuration,use_gh_userstill emits the generic missing-login message, andgchides the configuration error for every affected PR.- Suggested fix: Suppress only the redundant missing-token diagnostic, or retain both lines when their causes differ.
-
[README.md:284] — A pre-upgrade record is not the only way a github.com login reaches an Enterprise PR’s
pr.json. A current bare-number run in an Enterprise clone still selects a github.com login, resolves the Enterprise host afterward, and saves the login as given (lib/worktree.sh:425). Its nextgccan therefore skip it for exactly the documented legacy reason.- Suggested fix: Mention this case alongside older records and recommend using the full PR URL when the saved login must be the Enterprise one. No change to the agreed bare-number behavior is needed.
Recommendations
Extend the host/token tests in both directions: verify not only that the intended destination receives the selected credential, but also that an unrelated destination cannot receive it and an unrelated account cannot block it.
Assessment
Ready to merge? No
Reasoning: The primary URL-based review and cleanup paths select the intended account, but Git can disclose its token to a different host, and preflight can reject a working credential. Both should be fixed before merge.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
-u exports the PR host's token as GH_ENTERPRISE_TOKEN, and gh auth git-credential answers every host but github.com with it. The helper was registered for every HTTPS host, so a mirror that an insteadOf rule sends the clone or fetch to (git asks the helper for the rewritten URL) received the PR host's token. Every other helper is still cleared; gh's is now set as credential.https://<host>.helper, the host as the URL git fetches from spells it (git_url_host).
gh auth status -h <host> checks every login gh stores for the host, and none that only an environment token gives without GH_HOST naming the host: another account's expired token failed a valid -u run, and a valid GH_ENTERPRISE_TOKEN with no stored login was refused. The preflight now reads the account with gh api --hostname <host> user, once, with the run's environment, and keeps the host's own error. The round history's check reuses that login when the host is the same (the PR's URL host); a bare number in another host's clone still reads it there.
…e numbers in Enterprise clones gc dropped every line but use_gh_user's when a login was missing, hiding gh's reason when it was another (a config it can't read). Only gh's 'no oauth token found' line, which use_gh_user's repeats, is dropped now. README: a bare-number run in an Enterprise clone saves a github.com login too, which gc may then skip; pass the full PR URL for the Enterprise login to be saved.
|
Thanks for round 1. All four findings are fixed in three commits ( Critical
Important
Minor
Checks on
|
catalan-adobe
left a comment
There was a problem hiding this comment.
Round 2 · since round 1
3 fixed · 1 still open · 2 new (2 in the new commits) · open blocking: 2 (was 2) · loop: early
Approach
Unchanged since round 1: Review and gc still use the shared account-selection helper, and the revised preflight and Git credential helper now check and use the selected token only on its intended host.
Approach: Sound
Strengths
gh-pr-review:396checks the credential the run will actually use, andgh-pr-review:536reuses the returned login only when the resolved PR host matches. An expired token belonging to another account no longer blocks the review.lib/gc.sh:611–619isolates account selection per PR, preserves actionablegherrors, and continues the batch after a failed lookup.tests/gc.sh:1203–1220checks both the credential used for a successful read and the absence of a PR query after a failed lookup.
Issues
🚨 Critical (Must Fix Before Merge)
-
F1 · [gh-pr-review:656] — The host-scoped helper fixes ordinary clone and fetch requests, but it is not the only way Git can obtain the selected token. On a
*.ghe.comrun,-uexports the selected token asGITHUB_TOKEN(lib/common.sh:77–78). If a runner’sGIT_ASKPASSadapter supplies that variable, an HTTPS mirror that does not match the helper falls back to askpass and receives the PR host’s token. The new test unsets askpass and disables terminal prompting (tests/flow.sh:363–365); the production commands do neither.- Checkout is another uncovered path:
lib/worktree.sh:399,:420, and:469usergitwithoutGIT_AUTH. A Git LFS download during checkout can therefore invoke a user-configuredghhelper for a second Enterprise host while the first host’s token is exported. - Suggested fix: Keep the selected token out of the general Git process environment and make it available only to the helper for the matching host. Apply that policy to checkout operations that can fetch LFS content as well as to explicit clones and fetches.
- Checkout is another uncovered path:
-
[gh-pr-review:396] — Without
-u, the new preflight can send an ambient Enterprise token to an unrecognized host. For example, ifGH_HOSTnames the company server andGH_ENTERPRISE_TOKENholds its token, passing a PR URL on a different, unconfigured server causesgh api --hostnameto send the token there on its first/userrequest. A rejected request still discloses the credential. The previous host-inventory check stopped before contacting such a host.- Suggested fix: For an ambient Enterprise token, require a trusted host binding independent of the PR URL, such as a matching
GH_HOSTor an explicitly configured host. Keep the direct/userprobe for the bound host; there is no need to restore the all-accounts check.
- Suggested fix: For an ambient Enterprise token, require a trusted host binding independent of the PR URL, such as a matching
⚠️ Important (Should Fix)
(none found)
💡 Minor (Nice to Have)
- [gh-pr-review:396] — Discarding the probe’s stderr turns transport and hostname errors into incorrect login instructions. With real
gh2.97, a:8443URL producedgh not authenticatedand advised logging in with that port, whileghitself reportedinvalid hostname. A proxy failure is likewise not fixed by logging in again.- Suggested fix: Preserve the first diagnostic from
gh, asoperator_logindoes, and describe the failure as inability to verify the account unless authentication was actually refused.
- Suggested fix: Preserve the first diagnostic from
Fixed since the last round (3)
- F2 — Preflight probes the effective credential directly instead of checking every stored account (
gh-pr-review:396). - F3 —
gcretains configuration errors and suppresses the redundant missing-token diagnostic (lib/gc.sh:616). - F4 — The cleanup documentation now covers bare-number Enterprise runs and recommends the full URL to save the Enterprise login (
README.md:287–294).
Recommendations
Add negative tests for both boundaries: a Git operation with the caller’s credential adapters enabled, and a preflight where the URL host differs from the host bound to the ambient token. Assert that the unrelated destination is never offered the credential, not merely that authentication fails.
Assessment
Ready to merge? No
Reasoning: Account selection and gc now behave correctly on the intended host. The remaining blockers are credential disclosure paths: Git can obtain the selected token outside the scoped helper, and preflight can offer an ambient token to an unrelated server.
Review generated by gh pr-review · model: azure-openai-direct/gpt-6.2-astra
…rd prompt; the PR host's helper reads it from a private file Every git command the run starts (rgit, rgit_net, the delta fetches, the tripwire, the checks) runs without GH_TOKEN, GITHUB_TOKEN, GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN, with GIT_ASKPASS and SSH_ASKPASS empty and GIT_TERMINAL_PROMPT=0; checkouts (worktree add, checkout: Git LFS) get GIT_AUTH too. The helper for the PR's host reads the token gh reads for that host from a 0600 file in a private temporary folder, removed when the run ends.
…r GH_HOST binds Without -u, gh sends an Enterprise token of the environment to whatever host the PR URL names. The preflight now requires that host to be github.com, the one -u found the login on, the host GH_HOST names, or one gh stores a login for (gh config get --host <host> user: gh's own config, no request), and stops otherwise before any gh call to it: gh has no login for <host>.
|
Thanks for round 2. Under this PR's rule, only critical findings get fixed after round 2, and then it merges. The minor (keeping gh's own error in the startup check) is filed as #33. Critical
Also: I ran this branch against a real PR. Checks on
|
Fixes #29. The review run (including
--check) andgcnow look-u <login>up on the PR URL's host, asshowandroundshave done since #28.Why
The dashboard's review (#30) found the effect. On an Enterprise PR,
gh pr-review <GHE URL> --check --json -u alicecould succeed with alice's github.com login. The review then posted as whichever account was active on the Enterprise host. The account shown was not the one that posted.Change
use_gh_user "$GH_USER" "$(url_api_host "$TARGET")". It runs once, before anything else, so every gh call uses that account's token for that host:--check, the PR reads,operator_login, the post. So does git's credential helper:gh auth git-credentialreturnsGH_ENTERPRISE_TOKENfor a GHE host, which I checked with the real gh. A bare PR number stays a github.com login, andpr.jsonstill saves the login as given.gc: looks the saved login (or-u) up on the PR's host, taken from the state folder. A github.com PR is unchanged. With no such login on that host, the PR is skipped with "no gh login for '' on ", the other PRs are still processed, and gc exits 1. That is gc's existing rule for a PR whose state can't be read.-uon a*.ghe.comPR always failed:use_gh_userputs that account's token inGH_TOKEN, which gh also reads for github.com, and github.com refuses it. A GHE PR now needs a login on the GHE host; the error saysgh auth login --hostname <host>. A bare number and--doctoralone still check github.com.credential.helper=clears any others. With round 2's fix, every git command the run starts, checkouts included, runs without the four GitHub token variables, without askpass and without a terminal prompt. The PR host's helper reads the token from a private 0600 file, so a mirror, an askpass program or a Git LFS download never receives it.-ufound a login, the hostGH_HOSTnames, or one with a login in gh'shosts.yml(gh config get --host <host> user, which sends nothing). Otherwise the run stops before contacting it.gh api --hostname <host> userwith the run's own token, which also gives the login the run reads later.-uis a login of the PR URL's host for every command; a bare number means github.com;statusis unchanged. It also documents gc's rule.Tests
The stub gh in
tests/flow.shandtests/gc.shnow logs each call's host and the token gh would read for it.Review run (
flow): these failed on291a5f4:-u aliceonGHE.example.com:443, the run posts and every call carries alice's GHE token: the startup check, the PR reads, the user read and the POST;--check --json -u aliceon GHE does the same;-u aliceonacme.ghe.com, every call carries alice's token there;-u ci, which only has a github.com login, on GHE: exit 1 naming the host, with no other gh call, no git call and no model call;ghe.local, wherepr.jsonsavesalice.Controls: a github.com PR with
-u, and the existingGH_HOSTtest.gc: a GHE PR saved with alice is read with her GHE token and removed. bob, who has no GHE login, is skipped with the reason and not queried, and gc exits 1. With-u alice, each PR is read with her token on its own host. The github.com control is unchanged.Results
flow369,gc218);flow,gc,showandroundsalso pass on/bin/bash3.2.dash/:cargo testpasses with the contract test required.