Skip to content

Refuse a Blanket Stage in Any Checkout With an Origin and Pin the Rules Read's Host - #4511

Open
ptr727 wants to merge 6 commits into
developfrom
feature/guard-blanket-add-and-host-pin
Open

ptr727 wants to merge 6 commits into
developfrom
feature/guard-blanket-add-and-host-pin

Conversation

@ptr727

@ptr727 ptr727 commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Closes #4462
Closes #4501

Both designs were approved at the 2026-11-26 triage (answer comments on each issue). The merge waits on the maintainer's go-ahead after he reads the diff.

What changed

  • Refuse a Blanket git add in Linked Worktrees, Not Only in a Primary Checkout #4462, README requirement 11. A git add or git stage naming no explicit file, and a git commit -a, --all, or sweeping commit pathspec, is refused in any checkout with an origin, primary or linked. A repository with no origin passes. -N, -p, -v with named files and the read-only -n / --dry-run pass. One _explicit_paths predicate is shared with requirement 6's in-place exemption. git stage is added to requirement 6's always-deny set. --git-dir, GIT_DIR, and a run-time cd / -C directory read as having an origin, so they deny.
  • Pin the GitHub Host for the Write Guard's Branch-Rules Read #4501. _live_branch_rules passes env={**os.environ, "GH_HOST": "github.com"}, a standalone copy of Pin the GitHub Host for Every gh Child the Hub Scripts Start #4502's pinned_env(). A selftest sets GH_HOST=other.example and asserts the child sees github.com, and fails when the pin is removed.
  • Selftest. New cases for each shape above, plus _blanket_live_selftest, which runs classify against a real origin, a real linked worktree, a real repository with no origin, and a --git-dir from elsewhere.

Compacted (no behavior change)

The guard sat at 2496 of its 2500-line ceiling, which is not raised. Three selftest case tables, _CASES, _IN_PLACE_CASES and _CHECKOUT_CASES, are now |-delimited strings expanded at import into the same tuples. Before and after, the full --selftest output sorted line by line is identical apart from the added cases, and a review pass compared the expanded tables as multisets (130, 61 and 65 entries both sides). The guard is now 2494 lines.

Maintainer diff read owed

Everything under host-setup/agent-safety/ changed:

  • claude/gh-write-guard.py: _blanket_denial (new, wired into classify before the wait check), _explicit_paths and _NOT_EXPLICIT (the shared predicate, extracted from _in_place_allows), _ORIGIN_URL, an add entry in _OPTION_VALUES, stage in _ALWAYS_DENY_SUBS, the GH_HOST env in _live_branch_rules, the selftests, and the three packed case tables.
  • README.md: new requirement 11, a pin sentence in requirement 4, stage in requirement 6's denied list, and requirement 11 in the text-judging sentence.

Declined

  • The mkdir-then-add race, and git remote add origin && git add -A in one command: "needs a compound command crafted to dodge the guard, not the accident this guard exists for" (maintainer ruling on Refuse a Blanket git add in Linked Worktrees, Not Only in a Primary Checkout #4462).
  • git add <submodule dir or symlink> is refused as a directory, per the strictest-default rule.
  • A crafted env --chd= abbreviation, and a --git-dir / --work-tree pair split from the cwd.

Local review: findings still open after the edit budget

Six local passes ran, each fix answered by a fresh pass. The sixth, at the pushed head, raised 3 findings, all introduced. The two earlier rounds' findings were fixed or declined above. These go to the review loop:

  1. gh-write-guard.py:1262: brace expansion (git add {.,a.txt}, git commit {-a,-m} x) reads as one plain path and passes. The same spelling already passed requirement 6's in-place exemption at the merge-base.
  2. gh-write-guard.py:1257: _explicit_paths now also refuses run-time words ($, backtick) for the in-place rm and mv, which allowed them before. README requirement 6 says only an add path must not name a run-time word, so the sentence or the behavior needs to change.
  3. gh-write-guard.py:1292: git commit --mess "fix docs/" is refused, since a unique abbreviation of --message is not read as taking a value and the message's trailing / reads as a directory. Low impact.

Also open: no selftest pins the glob-character exception (a path with a glob character passes only when it names an existing file that no other file matches as a glob). Two reviewers disagreed on whether git needs that strictness, and the strict form is kept.

Declined with the same reason as above: xargs git add {} and similar shapes the lexer does not read, per README "a shape the lexer does not read is allowed".

🤖 Generated with Claude Code

ptr727 and others added 3 commits November 26, 2026 20:57
…es Read's Host

Requirement 11 refuses git add naming no explicit file and commit -a in a primary or linked checkout with an origin, sharing one path predicate with the in-place exemption. The live branch-rules read passes GH_HOST=github.com to its child.

Closes #4462
Closes #4501

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…rd's Case Tables

Treat git stage as git add, read separate-word option values, judge commit pathspecs, honor --git-dir and GIT_DIR for the origin read, and allow read-only dry runs. A live selftest reads a real origin. The case tables pack into delimited strings, with no case removed, to hold the 2500-line ceiling.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…Abbreviation

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings November 27, 2026 05:17
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 97c5a31 and 8c3b807.

Files selected for processing: 3

  • host-setup/agent-safety/README.md
  • host-setup/agent-safety/claude/gh-write-guard.py
  • host-setup/agent-safety/claude/test_install.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 7b78a36f06a64f3f07f9185950bb402e2af1cefe, the content this pull request carries at that commit against develop, and it recorded 8 findings.

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.88312% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.07%. Comparing base (b38e084) to head (8c3b807).
⚠️ Report is 372 commits behind head on develop.

Files with missing lines Patch % Lines
host-setup/agent-safety/claude/gh-write-guard.py 16.88% 64 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4511      +/-   ##
===========================================
- Coverage    81.60%   79.07%   -2.54%     
===========================================
  Files           26       50      +24     
  Lines         9070    16901    +7831     
===========================================
+ Hits          7402    13365    +5963     
- Misses        1668     3536    +1868     
Flag Coverage Δ
python-3.13 79.07% <16.88%> (-2.54%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved critical and moderate findings leave the staging guard vulnerable to bypasses and incorrectly reject valid commands, so the active issues must be addressed before approval.

8 open issues
What changed in this PR

This PR strengthens the host-safety guard against blanket Git staging and prevents branch-rule reads from honoring an inherited GitHub host.

Changes:

  • Adds requirement 11 for explicit-path staging and commit operations in repositories with an origin.
  • Shares path validation with primary-checkout exemptions and adds git stage handling.
  • Pins live branch-rule queries to GH_HOST=github.com and expands self-test coverage.
File Description
host-setup/​agent-safety/​README.md Documents blanket-stage protection and the pinned branch-rule host behavior.
host-setup/​agent-safety/​claude/​gh-write-guard.py Implements origin-aware staging checks, shared path validation, host pinning, and expanded self-tests.

Review effort: Lite

ptr727 and others added 3 commits November 26, 2026 21:35
Normalize git stage to add, read --attr-source's value, scan parsed flags for --pathspec, treat run-time words as non-explicit, let a glob-named existing file stage, and skip the git-spawning live selftest under the ntpath test.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

A recorded local strict-review pass covers head 8c3b807002f63ba133426e8135f1427b9e4aac80, the content this pull request carries at that commit against develop, and it recorded 3 findings.

@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@ptr727

ptr727 commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

/review

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

This branch has not been deployed

No deployments
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.

2 participants