Repository navigation
Keep a Bare Push's Branch Unresolved Behind an Unrecognized env Option in the Write Guard - #3731
Conversation
…n in the write guard Behind an env option the guard does not recognize, a push naming no refspec or HEAD no longer reads its branch in the caller's directory with the command-carried GIT_DIR. Unless an absolute --git-dir, git -C, or cd names the repository, it is read as writing every branch protected by default, so a protected default fails closed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-branch anchor Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
|
A recorded local strict-review pass covers head |
…self-test Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
The change has three unresolved nit-level issues: missing reason-regression assertions and documentation or denial guidance that do not fully describe absolute anchor behavior, including wrapper-body cd.
3 open issues
What changed in this PR
This pull request hardens the write guard against bare or HEAD pushes hidden behind unrecognized env options. It removes unsafe repository-context fallback behavior and fails closed unless an absolute repository anchor resolves the target branch.
Changes:
- Removes the lenient
GIT_DIRfallback and expands unresolved bare pushes to protected default branches. - Updates branch-target expansion, denial messaging, and regression tests.
- Documents the new behavior and supported repository anchors.
Review findings remain:
- Moderate (1 vote): Scope the unresolved-branch denial reason to only the targets produced by the expansion.
- Nit (4 votes): Add self-test assertions for denial reasons on bare and
HEADpushes. - Nit (4 votes): Clarify that only absolute anchors, including wrapper-body
cd, resolve the repository. - Nit (2 votes): Include wrapper-body
cdin the denial remediation message.
| File | Description |
|---|---|
host-setup/agent-safety/README.md |
Documents fail-closed handling for unresolved bare and HEAD pushes behind unrecognized env options. |
host-setup/agent-safety/claude/gh-write-guard.py |
Updates repository resolution, protected-branch expansion, denial messaging, and self-test coverage. |
Review effort: Lite
…n its env-option condition Co-Authored-By: Claude Opus 5.5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3731 +/- ##
========================================
Coverage 82.02% 82.02%
========================================
Files 27 27
Lines 9275 9275
========================================
Hits 7608 7608
Misses 1667 1667
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
A recorded local strict-review pass covers head |
…the guard self-test Co-Authored-By: Claude Opus 5.5 <[email protected]>
… seam Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…s expansion Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…e the wrapper-body cd remedy Co-Authored-By: Claude Opus 5.5 <[email protected]>
…al keeps its reason Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
A recorded local strict-review pass covers head |
…d Unread Moves Whole, and Name uv's No-Cache Setting (#3715) Promotes the changes merged into `develop` since promotion #3703 to `main`, the third round of a backlog burndown. - [#3709](#3709) Reads a push's remote, and the branch of a push with no refspec, in the repository git actually uses in the write guard's owner check (requirement 4). Before, `--git-dir` and a `GIT_DIR` on the push were ignored, so a constructed `git --git-dir=<other>/.git push origin develop` was checked against the working directory's repository rules and allowed. A shape whose repository the guard cannot determine (an earlier `GIT_DIR`, a `-c` or `--config-env` override of a `remote.` or `url.` key, any `GIT_CONFIG*` variable, an unresolvable `--git-dir`) now blocks `main`, `master` and `develop`. The self-test covers each shape and `host-setup/agent-safety/README.md` states the requirement. - [#3712](#3712) Reads a file moved out of a source some rule never read in full for that rule in the prose gate: a narrowed directory scope, a `home_path_exempt` file, instruction text for `issue-ref`, and a move that changes the file's lexer. Skips YAML block scalars when reading a Compose file's volume entries. - [#3707](#3707) Names uv's no-cache setting, and its remedies, when the repo gate's resolved PyYAML interpreter is gone at launch, rather than reporting a bare missing-file error. - [#3708](#3708) Moves the section-name lookup key into one `section_key()` in `spec/fidelity_text.py`, used by the carry, the audit, the skill build and the review ledger, with no behavior change. - [#3722](#3722) Applies `env`'s directory and environment options to the command the write guard judges, answering this promotion's first review round: `env -C`/`--chdir` move the repository a relative `GIT_DIR` and the remote resolve in, `env -i`/`-u` clear a `GIT_DIR` that no longer steers the check, and `env -S` is read rather than skipped. A run-time directory reads as undetermined, which blocks `main`, `master` and `develop`. - [#3721](#3721) Finds a Compose block-scalar opener through the YAML lexer the gate already uses rather than a hand-written pattern, so a key holding `#`, quoted or not, opens the opaque region. Also answers this promotion's first review round. - [#3727](#3727) Reads an `env` option the write guard does not recognize, such as GNU `env`'s `--ch` abbreviation of `--chdir`, as leaving the push's repository undetermined, so `main`, `master` and `develop` fail closed, answering this promotion's second review round. A feature-branch push is never newly blocked. - [#3731](#3731) Removes the fallback #3727 kept for a push naming no refspec behind an unrecognized `env` option, answering this promotion's third review round. Such a push resolves its branch only through an absolute `--git-dir`, git's own `-C`, or a `cd` in a wrapper body, and is otherwise read as writing every protected default, so it fails closed even from a feature branch. Deferred review findings: #3705 (`scripts/README.md`'s uvx promise), #3706 (`validate.py`'s exact section-name match), #3710 (whether `section_key` should casefold), #3711 (Compose-name and directory moves in the prose gate), #3713 (the review reader's `open review findings:` spelling), #3714 (an edited shebang that changes a file's lexer), #3720 (the write guard's reading of `git push -o<value>`), #3723 (unused `_bare_push_branch` parameters), #3729 (a bare push after a branch switch earlier in the same command), #3732 (the review reader's `Review findings remain:` spelling). For the maintainer: #3730 asks whether every bare push whose repository the guard cannot determine should fail closed, as #3731 now does behind an unrecognized `env` option. Fixes #3695 Fixes #3684 Fixes #3694 Fixes #2358 Fixes #3686 Fixes #3716 Fixes #3717 Fixes #3725 Fixes #3728 🤖 Generated with [Claude Code](https://claude.com/claude-code)

Fixes a finding raised on promotion #3715.
Closes on promotion: #3728
What changes
_bare_branchinhost-setup/agent-safety/claude/gh-write-guard.pyread the branch a push naming no refspec (orHEAD) writes. Behind anenvoption the guard does not recognize, it fell back to reading that branch in the caller's directory with the command-carriedGIT_DIR, as if the option were absent. So from a feature branch,env --ch=/srv/other git push originwas judged on the caller's feature branch while git may pushmainin/srv/other.lenientread of_named_git_dirit alone used.--git-dir, git-C, orcdnames the repository, as the existing reading already does._bypass_denialreads the push as writing every branch protected by default, as--allis, so a protected default fails closed._push_targetsnow takes the branches a bare orHEADpush may write as a tuple, so that expansion has one home.main.host-setup/agent-safety/README.mdstates the new behavior and its cost once: such a push may be refused even from a feature branch.Verification
classifyon two constructed scratch repositories, one checked out onmainand the caller on a feature branch. Before:env --ch=<main repo> git push originallowed. After: denied.env --ch=<main repo> git push origin feature/xstays allowed, and an absolutegit -Cor--git-dirnaming the feature-branch repository is judged on its branch and allowed.HEADbehind an unknown option are refused, an absolute--git-dirorgit -Cbehind one resolves to that repository's branch, an absolutegit -Cnaming a feature-branch checkout behind one is allowed, the explicit-refspec feature push stays allowed, and an unresolved bare push with noenvoption stays allowed.gh-write-guard.py --selftest: SELFTEST PASS. Prose gate, ruff check and format, and pyright are clean.Local strict-review findings
The two findings the opening push listed as open (no row checked which reason a denial carries, and the
_bare_branchdocstring naming a plaincdas an anchor) are fixed in later commits on this branch. Self-test rows now mark the dedicated reason, pin both halves of the condition that chooses it, and, through the rules seam, pin that the expansion reaches each ofmain,master, anddevelopfor a bare,HEAD, and@push. Each row was checked against a mutant it must kill. The last local pass over the pushed head raised no findings.Copilot review on 7a3b468
cdremedy, a reason-regression self-test) are fixed and resolved.HEAD developwith a rule ondevelopkeeps the ordinary reason.Filed separately
pr_review.pyhas no spelling for Copilot'sReview findings remain:label, seen on this PR.envoption the same way (decision for the maintainer).🤖 Generated with Claude Code