Skip to content

-u is a login of the PR URL's host for the review run, --check and gc (fixes #29) - #32

Merged
catalan-adobe merged 10 commits into
mainfrom
review-u-host
Dec 1, 2026
Merged

catalan-adobe merged 10 commits into
mainfrom
review-u-host

Conversation

@catalan-adobe

@catalan-adobe catalan-adobe commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Fixes #29. The review run (including --check) and gc now look -u <login> up on the PR URL's host, as show and rounds have done since #28.

Why

The dashboard's review (#30) found the effect. On an Enterprise PR, gh pr-review <GHE URL> --check --json -u alice could 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

  • The review run: 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-credential returns GH_ENTERPRISE_TOKEN for a GHE host, which I checked with the real gh. A bare PR number stays a github.com login, and pr.json still 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.
  • The startup check: it now checks gh's login on the PR URL's host instead of always github.com. Without this, -u on a *.ghe.com PR always failed: use_gh_user puts that account's token in GH_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 says gh auth login --hostname <host>. A bare number and --doctor alone still check github.com.
  • Git and the token: with round 1's fix, gh's credential helper is registered only for the PR's HTTPS host, and 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.
  • Unknown hosts: before any gh call to a host other than github.com, the host must be bound independently of the PR URL. That means the host where -u found a login, the host GH_HOST names, or one with a login in gh's hosts.yml (gh config get --host <host> user, which sends nothing). Otherwise the run stops before contacting it.
  • The startup check: one gh api --hostname <host> user with the run's own token, which also gives the login the run reads later.
  • README: -u is a login of the PR URL's host for every command; a bare number means github.com; status is unchanged. It also documents gc's rule.

Tests

The stub gh in tests/flow.sh and tests/gc.sh now logs each call's host and the token gh would read for it.

  • Review run (flow): these failed on 291a5f4:

    • with -u alice on GHE.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 alice on GHE does the same;
    • with -u alice on acme.ghe.com, every call carries alice's token there;
    • a token the PR's host refuses: exit 1 at the startup check, naming the host;
    • -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;
    • a round in a local clone on ghe.local, where pr.json saves alice.

    Controls: a github.com PR with -u, and the existing GH_HOST test.

  • 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

  • Tests: every test file passes on macOS bash 5 and Ubuntu 26.04 (flow 369, gc 218); flow, gc, show and rounds also pass on /bin/bash 3.2.
  • dash/: cargo test passes with the contract test required.
  • Lint: clean.

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 catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:229 selects the account before preflight, PR reads, or posting. tests/flow.sh:389–405 checks 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–619 keeps 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–1213 checks 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_user exports GH_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 Git insteadOf rule routes a clone through a separately authenticated HTTPS mirror, Git asks for the mirror’s credentials. Real gh auth git-credential uses GH_ENTERPRISE_TOKEN for 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 gh helper 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.

⚠️ Important (Should Fix)

  • [gh-pr-review:391] — gh auth status -h checks the host’s account inventory, not just the credential the review will use. With valid -u alice and an expired stored token for Bob on the same Enterprise host, real gh exits 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 matching GH_HOST, auth status rejects the host before testing the token. The stub at tests/flow.sh:110 models 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 later operator_login check. Add cases for a stale unrelated account and an environment-only credential.

💡 Minor (Nice to Have)

  • [lib/gc.sh:614] — Selecting only the no gh login line discards the underlying error even when it is not a duplicate. For example, if gh auth token cannot parse its configuration, use_gh_user still emits the generic missing-login message, and gc hides 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 next gc can 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.
@catalan-adobe

Copy link
Copy Markdown
Owner Author

Thanks for round 1. All four findings are fixed in three commits (201c315, 36f548c, 5bb4ec4), and main (#31) is merged in. Every new test failed on dfc6a40; the controls, which pass on both, are labelled.

Critical

  • gh-pr-review:229/641 (the credential helper on every HTTPS host): fixed in 201c315.
    • GIT_AUTH keeps -c credential.helper=, which clears every other helper, and registers !gh auth git-credential only under credential.https://<host>.helper. <host> is git_url_host, the same string as in the clone URL.
    • Every git clone and fetch goes through GIT_AUTH: rgit_net in lib/clones.sh and the two fetches in lib/delta.sh.
    • Real git 2.55 compares the host without case, drops :443, keeps any other port, and asks for the URL after insteadOf. So a mirror gets no helper.
    • Test (offline, real git and gh, skip without gh): git credential fill through the clone's exact options gives the PR's host the fixture GH_ENTERPRISE_TOKEN. https://mirror.example/… gets no username or password, for both GHE.example.com:443 and GHE.EXAMPLE.COM. On dfc6a40 the mirror got the token.

Important

  • gh-pr-review:391 (the startup check checks gh's account list): fixed in 36f548c.
    • The startup check is now one gh api --hostname <host> user --jq .login with the run's own token, with the same host-specific messages.
    • The run reuses that login instead of calling operator_login again when the host is the same, so a run makes one api user call.
    • --doctor uses the same check and prints ✓ gh authenticated on github.com as <login>.
    • The stub now models auth status checking every stored login. Tests: valid -u alice with bob's expired token on the same host runs and posts as alice. An environment-only GH_ENTERPRISE_TOKEN, with no stored entry and no GH_HOST, runs. A refused token, or no login on the host, stops with exit 1, names the host, and makes one gh call.
    • One change: the startup check doesn't retry, as gh auth status didn't, so a brief network failure stops --check there.

Minor

  • lib/gc.sh:614: fixed in 5bb4ec4. Only gh's no oauth token found line is dropped, since use_gh_user repeats it. Other gh errors are kept. Test: a configuration parse error shows failed to read configuration: …; no gh login for 'dave' on ghe.example.com.
  • README.md:284: fixed in 5bb4ec4. A bare-number run in an Enterprise clone with -u also saves a github.com login, so gc may skip it. Use the full PR URL to save the Enterprise login.

Checks on 5bb4ec4:

  • Tests: every test file passes on macOS bash 5 (flow 378, gc 219) and on Ubuntu 26.04, where the 6 real-gh checks skip because gh isn't installed. flow, gc, show and rounds also pass on /bin/bash 3.2.
  • dash/: cargo test passes with the contract test required.
  • Lint: clean.

@catalan-adobe catalan-adobe left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:396 checks the credential the run will actually use, and gh-pr-review:536 reuses 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–619 isolates account selection per PR, preserves actionable gh errors, and continues the batch after a failed lookup. tests/gc.sh:1203–1220 checks 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.com run, -u exports the selected token as GITHUB_TOKEN (lib/common.sh:77–78). If a runner’s GIT_ASKPASS adapter 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 :469 use rgit without GIT_AUTH. A Git LFS download during checkout can therefore invoke a user-configured gh helper 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.
  • [gh-pr-review:396] — Without -u, the new preflight can send an ambient Enterprise token to an unrecognized host. For example, if GH_HOST names the company server and GH_ENTERPRISE_TOKEN holds its token, passing a PR URL on a different, unconfigured server causes gh api --hostname to send the token there on its first /user request. 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_HOST or an explicitly configured host. Keep the direct /user probe for the bound host; there is no need to restore the all-accounts check.

⚠️ 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 gh 2.97, a :8443 URL produced gh not authenticated and advised logging in with that port, while gh itself reported invalid hostname. A proxy failure is likewise not fixed by logging in again.
    • Suggested fix: Preserve the first diagnostic from gh, as operator_login does, and describe the failure as inability to verify the account unless authentication was actually refused.
Fixed since the last round (3)
  • F2 — Preflight probes the effective credential directly instead of checking every stored account (gh-pr-review:396).
  • F3 — gc retains 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>.
@catalan-adobe

Copy link
Copy Markdown
Owner Author

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

  • F1, gh-pr-review:656 and lib/worktree.sh (the token reaching git outside the host's helper): fixed in 3769431.
    • No token in git's environment: rgit runs git without GH_TOKEN, GITHUB_TOKEN, GH_ENTERPRISE_TOKEN and GITHUB_ENTERPRISE_TOKEN, with GIT_ASKPASS=, SSH_ASKPASS= and GIT_TERMINAL_PROMPT=0. Every git command the run starts goes through rgit; the reviewer's own sandbox is unchanged.
    • Commands that may reach the network: they use rgit_net, which also gets GIT_AUTH. That covers the clones and fetches, the delta fetches, and now the checkouts (worktree add, the reused worktree's checkout --force, and the --fresh checkout), so Git LFS downloads go through the same helpers.
    • How the helper gets the token: the token gh would use for the PR's host is written to a 0600 file in a private 0700 folder, removed on exit. The PR host's helper reads that file before calling gh auth git-credential, so only the path is on a command line. With no such token, the helper stays the plain gh helper and uses gh's stored login.
    • Tests: -u alice on acme.ghe.com with a GIT_ASKPASS that prints $GITHUB_TOKEN.
      • No git command, checkouts included, has any of the four variables, and checkouts carry the host-scoped helper.
      • With real git and gh, offline: the mirror gets no password and askpass is never called, while the PR host still gets alice's token.
      • tests/delta.sh checks the same for delta's commands.
      • These failed on 354d1a3.
  • gh-pr-review:396 (an ambient Enterprise token sent to an unknown host): fixed in 6232211.
    • Before contacting a host other than github.com, the startup check needs a binding that doesn't come from the PR URL: the host where -u found a login, the host GH_HOST names, or a host where gh config get --host <host> user gives a login.
    • That command only reads gh's hosts.yml; it sends nothing, whereas gh auth status tried every stored host. Otherwise the run stops: "gh has no login for → run: gh auth login --hostname (or set GH_HOST= for a token in GH_ENTERPRISE_TOKEN)".
    • No earlier gh call sends anything: use_gh_user's gh auth token reads the local store, a URL needs no resolve_target call, and for a bare number gh repo view refuses an unknown host.
    • Tests: with an ambient GH_ENTERPRISE_TOKEN and GH_HOST=ghe.example.com, a PR on other.example stops with exit 1, and no gh call reaches other.example. With only an environment token and nothing that binds the host, the run now stops. Controls: GH_HOST matching the PR host, a stored login, and -u.

Also: I ran this branch against a real PR. --check --json -u catalan-adobe returns "run", and --doctor shows ✓ gh authenticated on github.com as catalan-adobe.

Checks on 6232211:

  • Tests: every test file passes on macOS bash 5 and Ubuntu 26.04 (flow 386); flow, gc, show, rounds, worktree and delta also pass on /bin/bash 3.2.
  • dash/: cargo test passes with the contract test required.
  • Lint: clean.
  • CI: green (2331 ok, 3 skip, 0 FAIL). The first run failed while installing shfmt during an Ubuntu mirror outage; the re-run of the failed job passed.

@catalan-adobe
catalan-adobe merged commit 8e7181c into main Dec 1, 2026
3 of 4 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.

-u on the PR's host for the review run and gc (show and rounds have it since #28)

1 participant