fix(tools): harden shell command pattern-matching against flag-order and blocklist bypasses#6521
Merged
Merged
Conversation
bug-ops
enabled auto-merge (squash)
July 19, 2026 21:31
bug-ops
force-pushed
the
fix/6497-shell-guard-bypass
branch
2 times, most recently
from
July 19, 2026 21:40
ab9ba9f to
2a8b1be
Compare
…and blocklist bypasses Generalize the tokenized recursive/force-flag detector already used for .git/worktrees protection to the general root/home rm guard, closing bypasses via reordered (-fr), separated (-r -f), long-form (--force), and post-path flags. Restore the original literal substring patterns alongside the new detector as belt-and-suspenders coverage for chained, prefixed, and non-rm-anchored invocations. Expand the sub-agent network-deny blocklist to cover ssh/scp/rsync, openssl s_client, socat, common interpreter one-liners, and bash's /dev/tcp//dev/udp pseudo-devices. Unify ShellExecutor's dispatch-path blocklist check with the shared matcher so the hardening reaches the actual bash execution path, not just external callers. Closes #6497 Closes #6473
bug-ops
force-pushed
the
fix/6497-shell-guard-bypass
branch
from
July 19, 2026 21:55
2a8b1be to
7200d8d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.git/worktreesprotection (is_blocked_rm_worktrees) to the general root/homermguard, closing bypasses via reordered (-fr), separated (-r -f), long-form (--force), and post-path flags (rm / -f). Restores the original literal substring patterns inDESTRUCTIVE_PATTERNSalongside the new detector as belt-and-suspenders coverage for chained (cd /tmp && rm -rf /), prefixed (sudo rm -rf /), and non-rm-anchored invocations the tokenized detector alone can't see.NetworkScope::Deny/allow_network = falseblocklist (NETWORK_COMMANDS) from 5 to 16 entries, coveringssh/scp/rsync,openssl s_client,socat, common interpreter one-liners (python3 -c,perl -e,ruby -e), and bash's/dev/tcp//dev/udppseudo-devices via a new embedded-substring fallback matcher.ShellExecutor::find_blocked_command(the real bash-execution dispatch path) withcheck_blocklist's matching logic via a sharedmatch_blocklist_tokenshelper — these had drifted into separate, unsynchronized implementations, so the hardening above now reaches the actual bash tool dispatch path, not just external callers likeNetworkDenyToolExecutor/ACP terminal.NETWORK_COMMANDSandNetworkDenyToolExecutornow honestly disclose residual, out-of-scope bypass vectors (flag-insertion before-c/-e, versioned interpreter names, non-transparent wrapper commands) rather than implying full coverage.Closes #6497
Closes #6473
Test plan
cargo +nightly fmt --check— cleancargo clippy --profile ci -p zeph-tools -p zeph-subagent --all-targets -- -D warnings— clean, 0 warningscargo nextest run --config-file .github/nextest.toml -p zeph-tools -p zeph-subagent --no-fail-fast— 1955/1955 passed (22 new tests)cargo test --doc -p zeph-tools— 34/34 passedRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-tools -p zeph-subagent— cleangitleaks protect --staged --no-banner --redact— no leaksrmforms), with negative tests confirming no over-broad false positives (rm -f /tmp/x.log,openssl enc ..., relative paths all still allowed)