Skip to content

Pin the GitHub Host for the Write Guard's Branch-Rules Read #4501

Done

Description

@ptr727

host-setup/agent-safety/claude/gh-write-guard.py _live_branch_rules runs gh api on the rules/branches endpoint with no host and the inherited environment. So an exported GH_HOST moves the guard's branch-rules read to that other host.

Failure

With GH_HOST=other.example exported, a push to a github.com repository makes the guard read the branch rules from other.example. A 404 there fails closed. But a same-named repository on that host answers with its own rule set. The guard then judges a github.com push against rules that do not govern it.

Fix

Pin the host for this read, for example GH_HOST=github.com in the child environment, as #4489 does for the hub scripts. The hook is standalone and cannot import scripts/gh_graphql.py, so it needs its own pin. Add a test that runs the read with GH_HOST set to a constructed host and asserts the child still targets github.com.

Origin

Raised by the local strict review on the #4489 fix, against code that change did not touch. Filed under pr-review-conduct outcome 4 as a pre-existing correctness defect, since #4489's fix is claimed.

Activity

  1. added
    pre-existing
    on Nov 26, 2026
  2. ptr727 commented on Nov 26, 2026

    @ptr727
    OwnerAuthor

    Triage question, 2026-11-26.

    Do you approve pinning GH_HOST=github.com in the child environment of the write guard's branch-rules read, _live_branch_rules in host-setup/agent-safety/claude/gh-write-guard.py, plus a selftest case that proves the pin? Today that gh api repos/<owner>/<repo>/rules/branches/<branch> call names no host and inherits the session's environment. So an exported GH_HOST sends the read to another host. A 404 there fails closed. But a same-named repository on that host answers with its own rules, and requirement 4 then judges a github.com push against rules that do not govern it. That can let a push through that the real branch rules forbid. The file is under host-setup/agent-safety/, the agent's own guard, so a human approves every change to it. An approval here lets an attended run implement it and drive the pull request. The merge still waits on your go-ahead after you read the diff.

    Options:

    1. Approve the env pin with a selftest (recommended). The call passes env={**os.environ, "GH_HOST": "github.com"}, the same mechanism Pin the GitHub Host for Every gh Child the Hub Scripts Start #4502 gave the hub scripts through scripts/gh_graphql.py pinned_env(). The hook is standalone and cannot import that module, so it carries its own two-line copy. A selftest case runs the read under a constructed GH_HOST and asserts the child sees github.com. It is a small, fail-closed change to one function. Nothing is in flight on this file.
    2. Approve, but pin with --hostname github.com instead. gh api takes --hostname, so this works here too. It is equally small. It diverges from Pin the GitHub Host for Every gh Child the Hub Scripts Start #4502, which chose the environment pin because --hostname exists on gh api alone, so the hub would hold two pin forms.
    3. Decline and leave the read unpinned. No change to the guard. The bypass stays open for any session that exports GH_HOST, which is a fail-open path in a check whose README says it fails closed for a protected default.

    Evidence: #4501 body, filed from the local review on #4502. #4502 (merged, on main) pinned every hub-script gh child and listed this site as out of its scope. host-setup/agent-safety/README.md requirement 4 states the live-rules read and its fail-closed contract. On main, _live_branch_rules still runs gh api with no host and no env. The guard's tests live in its own --selftest matrix.

  3. added
    decision
    on Nov 26, 2026
  4. ptr727 commented on Nov 26, 2026

    @ptr727
    OwnerAuthor

    Maintainer's answer, 2026-11-26 triage: option 1, approved as a design. _live_branch_rules passes GH_HOST=github.com in its child environment, as a standalone copy of #4502's pinned_env(), with a selftest case proving the pin. The edit is under host-setup/agent-safety/, so an attended run implements it and the merge waits on the maintainer reading the diff.

  5. removed
    decision
    on Nov 26, 2026
  6. added a commit that references this issue on Nov 27, 2026
    ee90b1d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    pre-existing

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions