Repository navigation
feat(hook): warn when a Bash(rtk:*) allow rule is present - #4716
Open
xiaozou-second wants to merge 1 commit into
Open
xiaozou-second wants to merge 1 commit into
xiaozou-second wants to merge 1 commit into
Conversation
`Bash(rtk:*)` reads as "rtk's own commands" but also auto-allows every command rtk filters, including ones the user never allowed on its own — `rtk git push` runs without a prompt. `rtk init` (install and upgrade) and `rtk verify` now say so on stderr, once per broad rule per settings file; the hook path stays silent because its stdout is the host protocol. The predicate asks the existing matcher against three unrelated subcommands rather than re-deriving wildcard semantics, so `Bash(rtk)` (a word-boundary prefix, not an exact match) and `Bash(rtk*:*)` are caught while `Bash(rtk git:*)` and `Bash(rtk git push)` are not. `Bash(*)` stays unflagged: it is not rtk-specific, and narrowing it to an rtk rule would misdescribe what the user allowed. The call sits at the end of the `Commands::Init` arm, so the per-agent branches (gemini, pi, trae, …) warn too, not only the shared Claude path. `--dry-run`, `--show`, uninstall and `verify --filter` stay silent. Also fixes `read_json` reporting a parse failure for an existing empty settings file, and spells both parse-failure paths with `display_path` so one run cannot name the same file two ways. Closes rtk-ai#4649.
📊 Automated PR Analysis
SummaryAdds a stderr warning emitted during rtk init and rtk verify when a Claude Code settings file contains a Bash allow rule that broadly matches every 'rtk ...' command (e.g. Bash(rtk:*)), since such rules also auto-allow underlying commands like rtk git push that the user never explicitly allowed. The check reuses the existing command_matches_pattern matcher against three probe commands to distinguish broad rules from legitimately narrow ones, and excludes the hook execution path and verify --fil… Review Checklist
Linked issues: #4649 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
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
rtk init(install and upgrade) andrtk verifynow print a stderr warningfor any
Bash(...)allow rule that grants everyrtk …command — e.g.Bash(rtk:*)reads as "rtk's own commands" but also auto-allowsrtk git push, which the user never allowed on its own. Closes Warn when a Bash(rtk:*) allow rule is present #4649.command_matches_pattern) againstrtk gain,rtk git pushandrtk cargo testrather than re-derivingwildcard semantics, so
Bash(rtk),Bash(rtk*:*)andBash(*rtk*)arecaught while
Bash(rtk git:*)andBash(rtk git push)are not.Bash(*)stays unflagged: not rtk-specific, and the "narrow it" advice would mislead.
Commands::Initarm, so the per-agent brancheswarn too; the hook path and
rtk verify --filterstay silent.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testManual testing:
rtk <command>output inspectedNew
tests/broad_rtk_allow_warning_test.rs: init /init -g --gemini/verify warn;
Bash(rtk git push),Bash(rtk git:*),Bash(*rtk),Bash(*)stay silent;Bash(rtk)warns; hook path andverify --filtersilent with a positive control and exit-status check; repeated rule warns
once.
Manual, temp
CLAUDE_CONFIG_DIR:verify,init -gandinit -g --geminieach warn for
Bash(rtk:*)andBash(rtk), silent forBash(rtk git push),Read(rtk:*)andBash(*);--dry-run,--show,verify --filter cargoand
hook claudewarn nothing.