feat(rules): support recursive wrapper command evaluation#45
Conversation
Commands like `sudo rm -rf /` or `bash -c "curl -X POST ..."` need to be evaluated by unwrapping the wrapper and checking the inner command against rules. Without this, users would need to duplicate every rule for each wrapper combination, causing combinatorial explosion. Add `extract_placeholder` to pattern_matcher for capturing tokens at `<cmd>` placeholder positions. Integrate wrapper unwrapping into `evaluate_command` via depth-tracked recursion (max 10), merging the inner result with direct rule matches using Explicit Deny Wins. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Summary of ChangesHello @fohte, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the rule engine's capability by introducing recursive evaluation for commands wrapped by common utilities like Highlights
Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
…king Compound commands inside wrappers (e.g., `bash -c 'ls; rm -rf /'`) were evaluated as a single command string, allowing dangerous sub-commands to bypass rule checks. Backtracking in the placeholder extractor also corrupted the captured token list. Split extracted inner commands via `extract_commands` so each sub-command is evaluated individually. Add `captured.truncate()` on backtracking to prevent stale tokens from leaking into results. Only capture tokens for `<cmd>` placeholders, not other placeholder names. Parameterize similar wrapper tests per project conventions. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Wrapper patterns containing Optional ([...]) or PathRef (<path:name>) tokens were silently falling back to basic matching, which could hide configuration mistakes from users. Now these cases return an explicit `UnsupportedWrapperToken` error instead of silently swallowing the issue. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`extract_placeholder_inner` only tried consuming exactly one command token when `<cmd>` was not the final pattern token. This caused multi-token inner commands to fail extraction for patterns like `wrapper <cmd> --flag`. Now it tries consuming 1, 2, ... tokens with backtracking, matching the Wildcard strategy. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
`extract_placeholder` joined captured tokens with a bare space, losing quoting information for tokens that contained spaces (e.g., `sudo echo 'hello world'` became `echo hello world`). Now `extract_placeholder` returns `Vec<String>` instead of a joined string, and `try_unwrap_wrapper` applies `shell_quote_join` for multi-token captures (structured commands like `sudo <cmd>`) while passing single-token captures as-is (shell scripts like `bash -c <cmd>`). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When a non-`<cmd>` placeholder (e.g., `<user>`) was the last token in a wrapper pattern, it incorrectly matched any number of remaining command tokens. Now it consumes exactly one token, consistent with `match_tokens_inner`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Why
sudo rm -rf /orbash -c "curl -X POST ..."need their inner commands evaluated against rulesWhat
<cmd>placeholder argument from wrapper patterns defined indefinitions.wrappers(e.g.,sudo <cmd>,bash -c <cmd>) and recursively evaluate the inner command against rulesRuleError::RecursionDepthExceededon overflow