Repository navigation
feat(guardrails): deny edits in a main checkout on its default branch - #16954
Conversation
block-main-checkout-edit runs on the Write|Edit|NotebookEdit row through run-guards.sh. It denies an edit to a file that is not git-ignored in a repository's main checkout while HEAD is on the branch origin/HEAD names, and the reason gives the steps to make the edit in a worktree. Linked worktrees, other branches, a detached HEAD, git-ignored paths, paths outside a repository and repositories with no origin/HEAD pass. Every check before one git check-ignore reads files with bash builtins, so the row's spawn count on a clean Write stays at 7. On by default; block_main_checkout_edit_enabled turns it off. Refs: #16905 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs
Refs: #16905 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs
|
Owner of this pull request: the hub session "Plugin Presets". This build session reports to it; route questions about the exemption design and the live-session check there. |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 587d235cf2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Lane run report
Failed GitHub API calls
|
Lane-Activity: pr-refine/fix-docs
Lane run report
Failed GitHub API calls
|
|
claude-review reviewed Incremental review: feat(guardrails): deny edits in a main checkout on its default branchScope: the change from My earlier summary finding is fixed. It said the manifest Hook changes I traced by hand (
Security. The ownership gate, unsetting the Not verified. I did not run the tests. The PASS counts in the PR are the author's claim. Closing issue. The PR context only says Usage. The change adds no new process on the common path. The only git process is still the one Loosened checks. Verdict: fail. This is the default, because the prompt has no Advisory and manifest lines (1)
Verifier dropped 0 of 0 candidates. |
|
claude-security-review reviewed Security review: PR #16954, incremental (c4681ec → 38f346c)This review covers only what changed since c4681ec, in 5 files: No security issues found in this push. The earlier CRITICAL finding is fixed. It was that a planted
Other changes:
Spend: none. critical-findings: 0 Manifest lines (1)
|
|
claude-security-review holds this pull request for a person (critical-security) at CRITICAL: plugins/guardrails/hooks/block-main-checkout-edit.sh:62/95 is on by default. On an ordinary Write or Edit it runs claude-lane: claude-security-review |
The manifest description now lists main-checkout edits on the default branch among the blocks, and counts 25 guards, the rows of the README guard table. Refs: #16905 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs
…ys off A planted .git (another user's /tmp/.git, a C:/.git, an extracted archive) could run its core.fsmonitor command when block-main-checkout-edit read the index through git check-ignore, and the guard's explicit GIT_DIR skipped git's safe.directory ownership check. The guard now runs git only when this user owns the work tree, the git directory and its config, and otherwise allows the edit with no git call. Every git call unsets the locating GIT_* variables, so safe.directory applies too, and passes --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null, which outrank the repository's config and its includes. The target's existing directories are resolved through symlinks before the repository is found, so alias/a.txt with alias -> src is judged as src/a.txt instead of check-ignore failing beyond the symlink. A check-ignore error in an owned repository now denies, naming the error, instead of exempting the edit. Refs: #16905 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs
Refs: #16905 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs
|
@codex review |
|
Codex Review: Didn't find any major issues. Swish! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Live check by the hub session at the owner's request, Claude Code 2.1.327, head 38f346c, in a throwaway repository on its default branch with this branch's guardrails loaded through
The security lane cleared its hold in its re-review of this head, so the |
Refs: #16905
Summary
Sessions that start in a repository's main folder sometimes edit tracked files there instead of in a worktree, and no hook stopped it. A new guardrails guard,
block-main-checkout-edit, now denies a Write, Edit or NotebookEdit to any file that is not git-ignored in a main checkout while it is on the remote default branch. The denial tells the session how to make the edit in a worktree. It denies and never asks, because a background session cannot answer a prompt.New denial on update: the guard is on by default for everyone who installs guardrails. To turn it off for yourself, set
block_main_checkout_edit_enabledtofalse(README, "How to set these"). The changelog fragment and README both say so.Fix
run-guards.shrow. A main checkout is one whose.gitis a directory, or a gitdir file whose directory has nocommondir. The default branch is read from the localrefs/remotes/origin/HEAD, with no network call.origin/HEADall pass. A repository that has anoriginremote but noorigin/HEADpasses with a stderr line naminggit remote set-head origin --auto. A new file that is not ignored is denied like a tracked one (owner Q1). There is no per-repository opt-out (owner Q2).AGENTS.mdas the source of its worktree convention, gives both routes (/source-control:worktree create, orgit worktree addwithout entering it in a headless session), and gives the path to repeat the edit at.hooks.json,plugin.json(kill switch),guard-requires.sh, the abort boundary's guard list andrun-guards.test.sh's dispatch list.Verification
bash plugins/guardrails/hooks/block-main-checkout-edit.test.sh: PASS=88 FAIL=0. It runs on real git fixtures, both alone and throughrun-guards.sh, and covers a denied edit and new file, NotebookEdit, a tracked file under an ignored pattern, an inheritedGIT_DIR, and a gitdir-file main checkout. It also covers each exemption, a linked worktree, a detached head, a non-default branch, the kill switch and the registration.run-guards.test.shPASS=752,abort-boundary.test.shPASS=391,coverage-manifest.test.sh32/32. Theguardrails-pretooluse-write-edit-spawnsratchet census still readsspawns=7(ceiling 7): every check beforegit check-ignoreuses bash builtins only.shfmt -i 2, the pre-commit comment lint, and the pre-pushcheck-affectedpass.Related
Remaining
Not delivered
The two
## Remainingitems above. This diff delivers the tests line: a denied edit, each exemption, a linked worktree, a detached head and a non-default branch in the main checkout.🤖 Generated with Claude Code
https://claude.ai/code/session_01KeBVgexJUYJe9Na3shvSfs