Skip to content

feat(guardrails): scope rsync --delete and --remove-source-files to allowed roots - #11313

Merged
melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9756-41092044338-1
Oct 30, 2026
Merged

melodic-automation-lanes[bot] merged 1 commit into
mainfrom
work-resolve-issue/issue-9756-41092044338-1

Conversation

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor

Closes #9756

Summary

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

block-root-delete-target now judges rsync the way it judges a recursive rm. With --del, --delete or a --delete-<mode>, the destination (last operand) is a target. With --remove-source-files (or --remove-sent-files), every source is a target. Each target goes through the existing root, empty, bare-variable, protected-tree and outside-allowed-roots arms. A remote operand (host:path, rsync: //) is left alone. When an unquoted brace or glob could change which word is last, every operand is judged. The Bash prefilter, the substitution-body prefilter and parallel's ::: item filter now also pass text holding rsync, and the header, README row and hook-budget note list the mechanism as covered.

Not verified

  • scripts/run-test-file.sh plugins/guardrails/hooks/block-root-delete-target.test.sh was not executed: this lane's Bash runs only the named wrappers, so the new cases are checked only by reading the code. Left to the PR's CI.
  • scripts/run-test-file.sh plugins/guardrails/hooks/run-guards.test.sh (including the #4528 long-command ceiling case) was not executed here, for the same reason. Left to the PR's CI.
  • The Bash|PowerShell row's added time was not measured as docs/conventions/hook-budget describes, because this lane cannot run the hook. The README budget note says what the code does (no new process; an rsync call now pays the tokenizer parse) but gives no timing figure. The measurement is left for
  • scripts/check-changelog-fragments.sh --check-required origin/main was not run with that argument; the lane's check-changelog-fragments wrapper (no arguments) passed. Left to the PR's CI.
  • --remove-sent-files and --log-format are handled as aliases of --remove-source-files and --out-format, but the current rsync man page I read does not list either. They are handled the cautious way, since an unknown option makes rsync exit without deleting anything.
  • tidy: the ai-slop deterministic detector (detect.sh) could not run under this lane's Bash policy, so pass 4 was only a manual read against the rubric (no em dashes or catalog phrases found in the changed lines). Passes 1 to 3 ran; the only edit was splitting one long sentence in the README row.

Fix

  • plugins/guardrails/hooks/block-root-delete-target.sh: new rdt_rsync_check called from rdt_check_segment's command-word dispatch. It reads rsync argv: options anywhere up to --; arguments of -e/-f/-T/-B/-M/- and of the man page's argument-taking long options and their aliases are skipped; under xa
  • plugins/guardrails/hooks/block-root-delete-target.test.sh: new section 2h. Nine rsync forms are each run against /, $HOME, a path outside the allowed roots (blocks) and a path strictly inside the tree (allowed). Added cases for ~, a C:/ drive root, /tmp, the scratchpad and the scratchpad itself, the
  • plugins/guardrails/README.md: the block-root-delete-target guard row describes rsync coverage and adds the rsync gaps to 'Not covered'. New hook-budget accounting entry for #9756.
  • .changes/guardrails/feat-9756-rsync-delete-targets-7c2e5b19.md: new minor changelog fragment for guardrails (written by hand: new-changelog-fragment refuses on a detached HEAD).

Verification

The runner ran each check from the base copy against 7e33ca8:

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

The run reports:

  • read https: //download.samba.org/pub/rsync/rsync.1: --del is an alias for --delete-during; --delete, --delete-before/-during/-delay/-after/-excluded/-missing-args delete on the receiver (dest); --remove-source-files: 'sender removes synchronized files (non-directory)'; synopsis SRC... [DEST], so t
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-changelog-fragments: 'All 8 changelog fragment(s) under .changes/ are valid.' (final run)
  • /home/runner/work/claude-code-plugins/claude-code-plugins/.lane/checks/bin/check-affected: '12 passed, 6 skipped over 4 changed files' (final run). An intermediate run failed shellcheck SC1083 on an unquoted { in a bracket pattern; fixed by quoting it.
  • fresh-context review subagent over the whole diff: found 5 issues (brace/glob changing the last operand, expansions read as remote hosts, substitution and parallel ::: prefilters missing rsync, missing option aliases, remote tests that could not fail); all 5 fixed and covered by new test cases. It t
  • The lane run: https://github.com/melodic-software/claude-code-plugins/actions/runs/41092044338

Left out: the items under Not verified.

Related

#9756

Lane-Activity: work-resolve-issue/resolve-issue
@github-actions

Copy link
Copy Markdown
Contributor

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

No security issues found in this pull request. critical-findings: 0

What I read. I read all four changed files in full: the hook change in plugins/guardrails/hooks/block-root-delete-target.sh, its test section 2h, the README row and budget note, and the changelog fragment. None of them matches a trusted path or touches a plugin manifest. There are no manifest <field> items.

Direction of the change. The change only adds refusals. A deleting rsync is now judged through the same rdt_delete_operand arm a recursive rm operand uses. The rsync prefilter text additions send more commands to the existing tokenizer parse. They remove no block list entry, allowlist entry or hold, so no guard is widened or softened. The deleted "Other delete verbs: rsync --delete" gap line is replaced by narrower declared gaps in the header and README, and the code now covers the old gap.

Logic checked in rdt_rsync_check.

  • Option-argument skipping. The list of long options that take an argument (written without =) and the cluster letters e f T B M @ match rsync(1). I found no case where a real operand is wrongly skipped, which would have hidden a target.
  • Operand selection. After --, words are treated as operands, as rsync does. An unquoted brace or glob makes it judge every operand, so a brace or glob cannot hide which word is last.
  • Empty target set. tg is never empty when it is expanded under set -u.
  • Remote-operand heuristic. An operand with two or more characters before the : and no / is skipped as remote. It skips nothing when the prefix holds $, a backtick or {, and a single-letter drive path is still judged. host:path, host::module and rsync:// are skipped, which matches rsync's own reading.
  • xargs and parallel. rdt_deleter=1 makes the items read count as the rsync's operands. The parallel ::: item filter and the substitution-body prefilter now also pass rsync, so parallel ::: 'rsync -a --del src/ /' and echo "$(rsync -a --del src/ /)" are judged.

Residual gaps. These gaps are declared in the hook header and the README, and they are not regressions:

  • an abbreviated long option such as --dele
  • a remote operand that points back at this machine, such as localhost:/
  • the paths a --files-from list names
  • rsync on the PowerShell tool

The guard is a command-text deterrent, not a sandbox, and the added coverage is strictly more than the base.

Cost. Nothing in the diff can start a billed resource. The only runtime effect is that a Bash command whose text contains rsync now pays the tokenizer parse. The README states the timing is not measured here and is tracked under #5946. That is hook latency, not spend, so it is not a hold.

Not verified. I could not run the test files, so I judged the test expectations only by reading them.

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed 7e33ca82019a9a225819d957d11c63b735732040: 0 finding(s), 0 as inline comments.

No blocking or advisory findings. I read the whole diff (4 files) and the closing issue #9756. I did not run anything: the test files were not executed, and the author's own report says they were not run either, so the new test cases are checked only by reading the code.

What I checked in rdt_rsync_check (plugins/guardrails/hooks/block-root-delete-target.sh):

  • Option scan: I compared the list of long options that take an argument against the rsync man page options I know of and found no omission that changes which word is last. The -e, -f, -T, -B, -M and -@ cluster letters skip the right next word, and the inner break followed by continue unwinds correctly. -- ends option parsing.
  • Targets: --del, --delete and --delete-<mode> judge the last operand, and --remove-source-files judges every earlier operand. A single operand returns early because it only lists. A brace or glob makes every operand a target.
  • Remote operands: host:path and rsync:// are skipped; a one-letter drive prefix and an expansion-built host are still judged, so the exemption cannot be used to hide a local root. The --time-limit 60 and --zl 3 tests exercise the option-argument skip.
  • xargs and parallel: setting rdt_deleter=1 after the delete-option check lets the appended items be judged. When there is one named operand, the early return 0 is safe because the items are judged by the caller. When there are two or more, the named last operand is also judged, which errs toward refusing.
  • Prefilters: the three prefilters (Bash, substitution body, parallel ::: items) all gain rsync. The $(rsync …) and parallel ::: 'rsync …' tests cover the last two.
  • Closing-issue criteria:
    • Deny cases for /, $HOME and outside the roots: met by section 2h.
    • Allow cases for inside the toplevel, the scratchpad and an allowed root: met by section 2h.
    • Quoted prose stays allowed: met by the git commit -m "rsync …" and echo cases.
    • The header and README row list rsync as covered and move the remaining gaps (abbreviated long option, --files-from paths, remote operand, PowerShell) into the declared gaps: met.
    • The README "Hook budget accounting" entry states the process count (no new process). Measured timing was moved to feat(guardrails): extend delete scoping to find, xargs, rsync and other deleters #5946 by the decision comment, so that is not a gap here.

Left for CI:

Declared limits (not findings):

  • A dry run (-n) is judged as if it ran.
  • Glob sources outside the roots with a delete option are refused, a known false positive.

Spend: none; this adds no billed resource, so no hold.

@melodic-automation-lanes

Copy link
Copy Markdown
Contributor Author

The unattended merge path armed native auto-merge at head 7e33ca82019a9a225819d957d11c63b735732040.

@melodic-automation-lanes
melodic-automation-lanes Bot added this pull request to the merge queue Oct 30, 2026
Merged via the queue into main with commit 0e920fe Oct 30, 2026
51 checks passed
@melodic-automation-lanes
melodic-automation-lanes Bot deleted the work-resolve-issue/issue-9756-41092044338-1 branch October 30, 2026 17:58
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.

feat(guardrails): scope rsync --delete and --remove-source-files to allowed roots

0 participants