Skip to content

fix: guardrails, disk-hygiene: narrow three destructive-guard matchers to their measured false positives - #10900

Merged
melodic-automation-lanes[bot] merged 5 commits into
mainfrom
work-resolve-issue/issue-9779-40831891732-1
Oct 29, 2026
Merged

melodic-automation-lanes[bot] merged 5 commits into
mainfrom
work-resolve-issue/issue-9779-40831891732-1

Conversation

@melodic-automation-lanes

@melodic-automation-lanes melodic-automation-lanes Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9779

Summary

Opened by the work-resolve-issue lane. The run's own summary:

The disk-hygiene engine gate now defers a Bash command when every simple command in it only reads (the closed reader set, sed -n '<range>p', quoted-delimiter heredoc bodies), even when it names the engine by its own path. block-dangerous-git lets a single plain git reset --hard / git clean -f through when git places the work tree and common git dir under a temp root and HOME is not under one. block-root-delete-target's existing literal binding (S=<literal> SEP ...) now holds across later statements that cannot change S. Each guard still blocks every other shape; a fresh-context review found one bypass per guard, and all three are fixed and pinned by tests.

Not verified

  • The issue's test suites were not executed (bash plugins/guardrails/hooks/block-dangerous-git.test.sh, bash plugins/guardrails/hooks/block-root-delete-target.test.sh, bash plugins/guardrails/hooks/run-guards.test.sh, python3 -m pytest plugins/disk-hygiene/skills/clean/scripts): this lane runs only th
  • The repro-first evidence is now shown under "Done-when 1: before/after" below.
  • ci-status green on the PR head: a PR CI check, left to the PR's CI.
  • CI-only scanners (fixture-git-isolation, test-tmp-cleanup, portability-lint and the others check-affected lists as CI only) were not run here. The changed suites keep their EXIT traps and source the helper that clears GIT_DIR/GIT_WORK_TREE/GIT_CONFIG.
  • Tidy not run: the change spans two areas (plugins/disk-hygiene and plugins/guardrails) and about 540 changed lines, over the 1-area and 300-line tidy cutoffs.
  • Known residuals, documented in the code: a shell function or alias the session defined before the command could still set the bound variable in block-root-delete-target. The dangerous-git exemption trusts that the probe's git and environment match the command's.
  • git status shows untracked .bash_profile, .bashrc, .gitconfig, .idea, .mcp.json, .profile, .ripgreprc, .vscode, .zprofile and .zshrc at the checkout root. This run did not create them and the file tools cannot see them (they look like sandbox mount placeholders), so they are not part of this change

Fix

  • plugins/disk-hygiene/skills/clean/scripts/destructive_guard.py: new _bash_reads_only / _bash_list_segments / _heredoc_body_end / _sed_prints_lines; _engine_gate_relevant returns False for a Bash command whose every segment is a reader, before the identity and marker rules; the now-unreachable Bash b
  • plugins/disk-hygiene/skills/clean/scripts/test_hygiene.py: new stay-quiet test (readers naming the engine by absolute or resolving path, reader pipelines and lists, sed line ranges, quoted heredocs) and still-gates test (engine call beside a reader, unquoted or glued heredoc delimiters, here-strings
  • plugins/guardrails/hooks/block-dangerous-git.sh: new repo_is_temp_scratch (Bash tool, the command is one plain git invocation with no -c global, wrapper, alias, separator, quote, escape, expansion, redirection or glob; git rev-parse --path-format=absolute --show-toplevel --git-common-dir from the
  • plugins/guardrails/hooks/block-dangerous-git.test.sh: fixtures moved out of the temp tree to the checkout's gitignored .work/ (NOT_A_REPO stays in temp) with a premise check against the temp roots; new section with stay-quiet rows in a temp scratch repo and still-blocks rows (repo outside temp, -C o
  • plugins/guardrails/hooks/run-guards.test.sh: the attended-row fixture repo moved out of the temp tree so its reset --hard rows keep asserting the refusal.
  • plugins/guardrails/hooks/block-root-delete-target.sh: rdt_lit_shape now binds when the command opens with NAME=LITERAL SEP, with no later NAME=/NAME+=/NAME:=/NAME[, every $NAME a whole double-quoted word, no quote, backslash, $, backtick, glob or brace character elsewhere, and RDT_LIT_FORBID_RE ext
  • plugins/guardrails/hooks/block-root-delete-target.test.sh: flipped the 'several statements before the delete', 'second delete' and 'comment after the delete' rows to allowed; added stay-quiet rows (temp scratch literal across statements and a subshell) and still-blocks rows (literal outside the tree
  • plugins/guardrails/README.md: block-dangerous-git row names the temp scratch exemption; block-root-delete-target row describes the widened literal binding.
  • .changes/disk-hygiene/fix-9779-narrow-destructive-guards-a3c91e5d.md: patch fragment for the engine-gate narrowing.
  • .changes/guardrails/fix-9779-narrow-destructive-guards-7b2f40c8.md: patch fragment for the two guardrails narrowings.

Done-when 1: before/after

Each new stay-quiet row fails with origin/main's implementation and passes on this branch. The test files stay at the PR head; only the three implementation files (destructive_guard.py, block-dangerous-git.sh, block-root-delete-target.sh) were restored from origin/main for the "before" run. PR head 3fc7b6ecc27aa9abce5aaf9ab09230fdb7219408, origin/main 53459a70ba14789b91b049ad382dd87d03378414.

Shape Test row origin/main implementation This branch
reader list naming the engine (disk-hygiene) test_engine_gate_defers_a_reader_list_naming_the_engine FAIL (15 subtests) PASS
temp scratch repo temp scratch repo: git reset --hard (allowed), ... HEAD~1, git clean -fdx, git clean --force, from a subdirectory, git -C <temp scratch repo> reset --hard / clean -fd from outside temp, reset --hard allowed under the dispatcher too (direct, dispatched): 9 rows FAIL PASS
literal bound several statements before the delete a literal several statements before the delete allowed (direct, dispatched) FAIL PASS
scratch literal used, then deleted a temp scratch literal used, then deleted, allowed (direct, dispatched) FAIL PASS
second delete of the bound variable a second delete of the bound variable allowed (#9779) (direct, dispatched) FAIL PASS
comment after the delete a comment after the delete allowed (#9779) (direct, dispatched) FAIL PASS
delete inside a subshell a temp scratch literal deleted inside a subshell allowed (direct, dispatched) FAIL PASS
Run disk-hygiene test block-dangerous-git.test.sh block-root-delete-target.test.sh
This branch Ran 1 test ... OK PASS=920 FAIL=0 PASS=2870 FAIL=0
origin/main implementation FAILED (failures=15), AssertionError: True is not false at test_hygiene.py:10893 PASS=911 FAIL=9 PASS=2860 FAIL=10

The 9 and 10 "before" failures are exactly the rows above; the still-blocks control rows pass on both sides.

Commands: python3 -m unittest test_hygiene -k defers_a_reader_list_naming_the_engine (from plugins/disk-hygiene/skills/clean/scripts), bash plugins/guardrails/hooks/block-dangerous-git.test.sh, bash plugins/guardrails/hooks/block-root-delete-target.test.sh.

Verification

The runner ran each check from the base copy against 9571c1b:

  • scripts/check-changelog-fragments.sh --check: passed

The run reports:

  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changelog-fragments: all 6 fragments valid (run after the final edits).
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-affected: 13 passed, 5 skipped over 10 changed files. Earlier runs failed ruff (an unused engine variable in test_hygiene.py) and shell-portability (a \&lt; in a bash glob read as a GNU word boundary); both fixed, t
  • Fresh-context review subagent over the whole diff: three confirmed bypasses (a glued heredoc delimiter in disk-hygiene; builtins spelled with quotes, escapes, expansions or globs in the root-delete binding; an escaped or variable-built cd/GIT_ relocation in the dangerous-git exemption), one low arit
  • read https: //pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html: section 2.7.4 says that when any part of the here-document word is quoted, the delimiter is the word after quote removal and the body lines are not expanded, and that <<- strips leading tabs from input lines, incl
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/40831891732

Left out: the items under Not verified.

Related

#9779

Lane-Activity: work-resolve-issue/resolve-issue

@github-actions github-actions Bot 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.

claude-security-review: 2 inline finding(s) on 9571c1b9ced62f0bf21e82bf004387410bfe656e; the summary is in this lane's pull request comment.

claude-lane: claude-security-review

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed 3fc7b6ecc27aa9abce5aaf9ab09230fdb7219408: 0 finding(s), 0 as inline comments.

Security review of PR #10900, head 3fc7b6e. I found no security issues.

critical-findings: 0

No changed file matches TRUSTED PATHS:. No plugin.json or marketplace.json changed, so there are no manifest <field> lines. The PR narrows three destructive-command guards in guardrails and disk-hygiene, which are session-safety hooks. I read all three narrowings for a way to widen what they let through. I did not run the test suites.

disk-hygiene destructive_guard.py (_bash_reads_only, _bash_list_segments, _sed_prints_lines).

  • The new defer rule needs every simple command to pass _bash_without_string_data or _sed_prints_lines. That check rejects $, backtick, \, #, ;, lone &, |, <, >, (, ), {, }, \r and unquoted newlines in a segment (destructive_guard.py:849).
  • The splitter drops only a quoted-delimiter here-document operator and its body. Unquoted delimiters, glued delimiters, here-strings, an unterminated body and any backslash return None, which keeps the gate.
  • A comment cannot hide a fake here-document: a # stays in its segment and fails the reader check.
  • The reader set is unchanged apart from the added --output prefix check. That blocks git show/log/diff --output=<engine>, which would write over the engine. I found no reader flag in the set that runs the engine it names. The existing --pre, -c and -O guards still apply.
  • The sed reader accepts only -n -E -r -s -u -z options and a \d+(,\d+)?p script, with no operand starting with -.
  • The PowerShell lane is unchanged.

guardrails block-dangerous-git.sh (repo_is_temp_scratch).

  • The exemption applies only on the Bash tool when $COMMAND holds none of [ ] ; & | newline \r $ \ ' " ( ) { } < > * ? #, git is the first word, and no -cor--config*` global appears.
  • It then asks git itself, with the same locating options (-C, --git-dir, --work-tree, --namespace) replayed, where the work-tree top and the common git dir are.
  • Both must be under a temp root, and HOME must not be (block-dangerous-git.sh:543, :545). HOME under a temp root, a linked worktree whose main repo is outside temp, a gitdir symlinked outside temp, a failed probe, and a repo under /var/tmp not named by TMPDIR/TMP/TEMP all keep the block. HOME unset also keeps it (:523).
  • hook::under_temp_root accepts a temp-root candidate of /, but the HOME check turns that case into a block.
  • Residual, already documented in the PR: if an env var or shell state set in an earlier Bash call changes where git acts, the probe and the real command can differ. Candidates are GIT_DIR/GIT_WORK_TREE, or TMPDIR pointing at a broad directory that does not contain HOME. Neither is attacker input in this diff.

guardrails block-root-delete-target.sh (rdt_lit_shape).

  • The binding now needs the command to open with NAME=LITERAL SEP. The rest of the command must have no second NAME=, NAME+=, NAME:= or NAME[, no unquoted $NAME, and no quote, backslash, $, backtick, glob or brace outside the whole double-quoted "$NAME" or "$NAME/…" words (block-root-delete-target.sh:742-750).
  • RDT_LIT_FORBID_RE is a strict superset of the base list (:714).
  • Because the leftover text has no quote, escape or expansion, a builtin can only be spelled as a literal word that the forbid list reads. The list is a denylist, so a bash or zsh variable-setting builtin it omits would be a gap. I found none in bash. A zsh module builtin such as zsystem flock -f needs zmodload first, and zmodload is on the list.
  • A symlink created inside the same command (ln -s … "$S/l"; rm -rf "$S/l/x") is not newly reachable: the same literal rm -rf /tmp/x/l/x already passes the allowed-roots test without the binding.
  • The remaining shell-function/alias residual is documented in the PR.

Tests and docs. The test fixtures move out of the temp tree and add premise checks, so the existing "still blocks" rows keep asserting a block. I read the README, changelog fragments and test changes and found nothing that removes a control without an enforcing replacement.

Spend. None. The change adds no model, turn or billing settings.

@github-actions github-actions Bot 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.

claude-review: 2 inline finding(s) on 9571c1b9ced62f0bf21e82bf004387410bfe656e; the summary is in this lane's pull request comment.

claude-lane: claude-review

@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed 3fc7b6ecc27aa9abce5aaf9ab09230fdb7219408: 1 finding(s), 0 as inline comments.

I found no correctness bug in the three guard changes, but one acceptance criterion from #9779 is not met. I read the whole diff (10 files) and the PR context, and traced the new code paths by reading them. I ran no tests (no shell in this lane).

Finding: acceptance criterion not met (blocking). #9779's Done-when says: "A stay-quiet test for each shape above fails on origin/main and passes on the PR branch (show both runs in the PR body)". The PR body says this "could not be produced here". It also says none of the four test commands the issue names (bash plugins/guardrails/hooks/block-dangerous-git.test.sh, block-root-delete-target.test.sh, pytest plugins/disk-hygiene/skills/clean/scripts) was run. The unchecked items are the before/after runs, the test-suite exits, and ci-status green on the head. The PR's own note that they are "left to the PR's CI and the PR author" does not meet them. The .test.sh rows in particular are new and unexecuted: the repo_is_temp_scratch probe, the .work/ fixture relocation, and the flipped root-delete rows. Run them, and show the failing-then-passing runs for each stay-quiet row, before merge.

Things I traced and found sound:

  • block-dangerous-git.sh: git_locating_opts always begins with -C <base>, so the probe cache key is never empty and cannot collide with the initial empty sentinel. temp_root_persists "$top" || temp_root_persists "$common" && return 1 parses as (a || b) && return 1, which is the intended "either persists blocks". block_clean_force is only called from inside check_segment, so $gi and $sub_idx are in scope.
  • destructive_guard.py: each segment still goes through _bash_without_string_data, which rejects <, >, #, $, backticks and parentheses. A redirect that writes the engine, or a # that hides a heredoc, therefore keeps the gate. _bash_list_segments returns None on a backslash, an unterminated quote, an unquoted or glued heredoc delimiter, or a body with no closing line. The --output prefix check closes the reader-writes-engine hole.
  • block-root-delete-target.sh: the widened binding requires a single leading assignment, no later NAME=, NAME+=, NAME:= or NAME[, every $NAME a whole double-quoted word, and no quote, backslash, $, backtick, glob or brace elsewhere. The forbidden-word list fails closed.

Accepted residuals, as the PR documents them:

  • A shell function or alias defined before the command can still set the bound variable.
  • The git exemption trusts that the probe's git and environment match the command's.
  • hook::under_temp_root counts a repository whose top level is the temp root itself, and any path if TMPDIR is set broadly. Both are environment-trusted.

Spend: none; no billed resource or setting changes.

Lane-Activity: pr-unblock/address-feedback
Lane-Thread: PRRT_kwDOTCGFQM6xdrXd
Lane-Thread: PRRT_kwDOTCGFQM6xdrXh
Lane-Thread: PRRT_kwDOTCGFQM6xdr1b
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

pr-unblock / address-feedback finished round 1 of max 4 on 08fec27.

@melodic-automation-lanes melodic-automation-lanes Bot added the needs-human Human-in-the-loop required; autonomous sessions must not resolve items carrying this. label Oct 29, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped on this pull request and needs a person: an adjudicator found that a disputed review finding turns on what the change is meant to do, which a person decides.

  • Reason: feedback-question-intent
  • Resume key: 08fec27dcd05f11ab52576c0ee3ff22d51027309 (the head the lane stopped on)

To resume, deal with the reason above, remove the needs-human label (and do-not-merge, if set), then dispatch the pr-unblock workflow with pr-number=10900 and activity=address-feedback:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=10900 -f activity=address-feedback

@melodic-automation-lanes

melodic-automation-lanes Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

The pr-unblock lane stopped address-feedback on this pull request: the pull request has an unresolved review thread the lane does not take (a reviewer it does not act on, a review of an older head, or a thread it already answered), so nothing will resolve it. The lane sets no label: the run ends in a failing pr-unblock/address-feedback status on the head the lane gated.

When a retry on this head can change the outcome, the lane runs one on its own, up to its per-head cap, and edits this comment if it stops again; a run that does not stop clears the status. When no retry can (a review thread the lane does not take or settle, or a failing check after the retries are spent), a person resolves the threads or gets the checks green, then dispatches the workflow below: that run finds the cause gone and clears the status. On a pull request the lanes App opened, the dispatchers start that run once per stop; on any other, a person does. A new commit to the branch starts clean.

To run it again on this head now, dispatch the pr-unblock workflow:

gh workflow run pr-unblock.yml -R melodic-software/claude-code-plugins -f pr-number=10900 -f activity=address-feedback

@kyle-sexton kyle-sexton removed the needs-human Human-in-the-loop required; autonomous sessions must not resolve items carrying this. label Oct 29, 2026
@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 3fc7b6ecc27aa9abce5aaf9ab09230fdb7219408.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit de60bdf Oct 29, 2026
84 of 86 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-9779-40831891732-1 branch October 29, 2026 15:29
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.

guardrails, disk-hygiene: narrow three destructive-guard matchers to their measured false positives

1 participant