Description
Problem
A read-only PowerShell loop over two local repositories was blocked by both block-no-verify and block-dangerous-git.
Session: Windows 11, Claude Code 2.1.278, auto mode, guardrails 0.35.0, PowerShell lane:
foreach ($d in 'cdtest','cdtest-cov') { $p="C:\Users\<user>\$d"; "== $d"; git -C $p remote -v; git -C $p status --short --branch | Select-Object -First 8; git -C $p log --oneline -3; git -C $p stash list }
- Message: "BLOCKED: this PowerShell command cannot be parsed with confidence ... Trigger: a construct the guard cannot faithfully tokenize (backtick, '--%', subexpression, or {}/() grouping)".
- Two long paragraphs in one denial, one per guard, although every git verb was read-only (
remote -v,status,log,stash list). - The denial also printed the canonical PowerShell commit form (here-string piped to
git commit -F -). The command had no commit. - The offered remedies were "run via the Bash tool" (Bash was blocked by another plugin's session belt, so no lane was left) or disabling
block_no_verify_enabled/block_dangerous_git_enabledglobally. - Workaround that passed: unroll the loop into flat
git -C <path> ...;statements.
Root cause
Traced by reading the installed source in lib/powershell/ps-command.sh; not executed (the audit session's Bash tool was blocked, so no reproduction ran and packet integrity is ungradable).
F2. Read-only allowance rejects remote -v and stash list; block-dangerous-git has no read-only allowance.
- The
{}and()grouping routes the command to the fail-closed sink (has_special_constructs, lines 801-809; triggerspecial-construct). - block-no-verify (
block-no-verify.shline 295,readonly-ok) asksps::git_command_is_readonly(lines 1436-1459). It uses a stem blocklist, and lines 1455-1456 listremoteandstashas mutating stems, soremote -vandstash listfail. - block-dangerous-git (
block-dangerous-git.shline 1400) uses the defaultmutatingscope ofps::classify_git_command(lines 1624-1667), which by the comment at lines 1621-1623 never consults the read-only test. Any git token inside any{}or()blocks.
F3. Denial text prints irrelevant commit guidance and dead-end levers.
ps::print_unparsable_block_message(lines 2025-2034) always prints "The canonical PowerShell commit form (a here-string piped to 'git commit -F -') is:", even without acommittoken.ps::print_sink_trigger_line(lines 1981-2018): every trigger line ends with "or run the command via the Bash tool" (for example line 1999). That is a dead end when Bash is blocked.- block-no-verify's only lever is the user-global kill switch (line 2033). block-dangerous-git offers the narrower
ps-unparsable-special-constructallow token (line 2047, and plugin.jsonblock_dangerous_git_allow). block-no-verify has no equivalent.
F4. No narrow lever for the PowerShell computed-call arm; scratch roots are Bash-lane only.
- plugin.json
block_hook_bypass_scratch_rootsis target-scoped, andblock-hook-bypass.shlines 501-503 state "SCOPE: Bash lane only". - For the guardrails:
& $var script record dirblocked as a file write; block reason names the wrong cause #4234 false positive, the only lever isblock_hook_bypass_enabled=false, user-global per the operator message at line 1186.
Harness doc read was rung 2 only (WebFetch of https://code.claude.com/docs/en/hooks.md, 2026-09-19, no byte count); harness-behavior quotes from it are unverified. None of these findings depends on more than "PreToolUse exit 2 blocks the call".
Not reviewed: block-noncanonical-commit, block-convention-violation, block-windows-drive-tmp, block-exported-msys-pathconv. They share the classifier and may share the "run via Bash" dead end.
Proposed fix
Cheapest first:
- Print the commit-form block only when the visible text contains a
committoken. - Lead each trigger line with the in-PowerShell rewrite ("unroll the loop into flat statements"); put the Bash suggestion second.
- Recognize read-only subcommand forms explicitly with an argument-aware check:
remotewith nothing after it, or with-v,show, orget-url;stash list;stash show. - Let block-dangerous-git use
readonly-oktoo, since its concern is destructive forms. Weigh this against the documented residual (aliases and-c core.pager) at lines 1420-1435. - Give block-no-verify an allow list with a
ps-unparsable-special-constructtoken matching block-dangerous-git's. - Add
block_hook_bypass_allow=ps-computed-positional(guardrails:& $var script record dirblocked as a file write; block reason names the wrong cause #4234, fix 3). - Invert the git read-only check to an allowlist, as the source comment at lines 1430-1432 already names.
Acceptance criteria
- The
foreachcommand above is allowed by both block-no-verify and block-dangerous-git. -
git remote -v,git remote,git remote show origin,git remote get-url origin,git stash list, andgit stash showpassps::git_command_is_readonly. -
git remote add x y,git stash pop, andgit stash dropstill fail it. - A blocked command with no
committoken produces a denial without the commit-form text. - Each trigger line names an in-PowerShell rewrite before any Bash-tool suggestion.
- block-no-verify accepts a narrow allow token for the special-construct sink.
- block-hook-bypass accepts a narrow allow token for the computed-call positional arm.
Found by /plugin-quality:audit (run 20260919T170952Z).
Activity
kyle-sexton commentedon Sep 23, 2026
This was generated by AI during triage.
Decision defaulted: adopt the issue's proposed read-only carve-out for
remote -v/remote/remote show/remote get-urlandstash list/stash showinps::git_command_is_readonly(), and give block-no-verify + block-dangerous-git the narrow allow tokens specified, gated on the issue's own acceptance-criteria tests (mutating forms likeremote add/stash pop/stash dropmust stay blocked) since this loosens two security guards — veto before mergekyle-sexton commentedon Sep 23, 2026
This was generated by AI during triage.
Agent Brief
Type: Bug
Summary: A read-only PowerShell loop over multiple repositories, using brace/parenthesis grouping, is blocked by two separate guards that treat any git token inside such grouping as unparsable and mutating, and the denial text offers guidance irrelevant to the actual command.
Current behavior:
A command containing brace or parenthesis grouping (such as a foreach loop) is routed by the PowerShell command classifier to a fail-closed "unparsable" path whenever the classifier cannot faithfully tokenize it. Two independent guards then act on that same fail-closed classification: one guard's read-only allowance rejects the command because its read-only check treats
remoteandstashas unconditionally mutating stems, so a git remote-listing or stash-listing call fails the read-only test even though neither mutates anything; the other guard does not consult any read-only test at all once a command is routed to this fail-closed path, so any git token inside brace/parenthesis grouping blocks regardless of verb. Both guards' denial text always includes a paragraph naming the canonical PowerShell commit form and suggesting the command be run through the Bash tool instead — printed even when the command contains no commit and even when the Bash tool is unavailable in the session. Only one of the two guards offers a narrow allow token for this class of block; the other guard's only lever is a user-global kill switch.Desired behavior:
Defaulted decision: the git read-only test in the PowerShell command classifier should treat
remote(bare, or with a verbose/show/get-url-style flag),stash list, andstash showas read-only, while forms such asremote add,stash pop, andstash dropcontinue to be treated as mutating. The guard that currently does not consult the read-only test at all when a command falls into the brace/parenthesis fail-closed path should be changed to consult it, so a read-only git command inside such grouping is allowed by both guards. Both guards should offer a narrow, documented allow token scoped to this fail-closed-grouping class, matching the allow-token mechanism already available on one of them. The commit-form guidance should print only when the blocked command's visible text actually contains a commit token, and any Bash-tool suggestion in a denial should come after, not in place of, a suggested PowerShell-native rewrite (such as unrolling a loop into flat statements).Maintainer-vetoable alternative: adopt only the narrow allow-token additions and the denial-text corrections (commit-form gating, rewrite-first ordering) without changing what counts as read-only, leaving remote/stash forms blocked inside grouping constructs unless the operator supplies the new allow token.
Key interfaces:
remoteandstash, rather than treating their bare stems as unconditionally mutating.Acceptance criteria:
Out of scope:
Merge origin/main into cursor/4235-ps-readonly-git-grouping-37e9
fix(guardrails): add block_hook_bypass_allow=ps-computed-positional (#…
docs(guardrails): document after-block continuation and PS over-blocks (
Merge origin/main into cursor/4235-ps-readonly-git-grouping-37e9
fix(guardrails): allow read-only git inside PowerShell grouping; narr…
fix(guardrails): add block_hook_bypass_allow=ps-computed-positional (#…
2 remaining items
docs(guardrails): correct released changelog entries in place
fix(guardrails): judge more shell shapes, declare node, correct docs (#…
fix(guardrails): block-dangerous-git lets read-only git through Power…
fix(guardrails): PowerShell sink denial offers the commit form only f…
fix(guardrails): release 0.42.1 with the PowerShell read-only git gro…
fix(guardrails): allow a computed PowerShell call whose target resolv…
fix(guardrails): exempt a literal PowerShell write under an exempt ro…
kyle-sexton commentedon Sep 30, 2026
Owner decision (2026-09-30): Option A on the CRITICAL security-review finding on PR #5548 (
ps-command.sh, theGIT_*environment-variable guard). Parse, do not substring-match: block anyEnv:write (Set-Item/New-Item/${env:...}/[Environment]::SetEnvironmentVariable) whose target name is not a literal string, fail closed. Add regression cases for a concatenated and a computedEnv:path. The owner accepted the recommendation on 2026-09-30 ("Go with recommendations").fix(guardrails): judge environment writes in the read-only git group …
fix(guardrails): judge a location change's operands as a write's are
docs(guardrails): name the location-change refusal in the 0.43.4 entry
fix(guardrails): allow read-only git inside PowerShell grouping (#5548)
kyle-sexton commentedon Oct 1, 2026
Owner decision (2026-10-01): approved the recommendation ("go with recommended", the owner's reply to the batch decision page that listed this question and its recommendation).
Question: close #4235 as completed now, or keep it open for the ps-computed-positional token?
Chosen: close as completed. PR #5548 (merge bd07e43) delivered the Agent Brief criteria, including the Env: guard. The block-no-verify token shipped via #4833. Criterion 7 (ps-computed-positional) is struck on the basis of the owner's close of PR #4817 ("neither is what #4235 asks for"); its target false positive, #4234, closed as completed. If the token is wanted later, file a new issue.
Next: close this issue as completed and remove the agent-ready label.