Repository navigation
fix(command-risk): see through wrappers and program paths, judge .. as the parent - #480
Merged
Merged
Conversation
… as the parent The risk gate matched the command word exactly against `rm`, `find`, … and skipped only `sudo`, `command` and `env`, so `/bin/rm -rf ~`, `timeout 5 rm -rf /`, `nice rm -rf ~`, `xargs rm -rf ~` passed as safe, and `sudo -u root rm -rf /` took `-u` for the command. A trailing `..` was stripped as a "glob", so `rm -rf ..` was judged in-project. - The command is the first word past assignments, keywords and known wrappers (sudo, doas, env, command, builtin, exec, nohup, time, nice, ionice, stdbuf, timeout, xargs) with their options, option values and leading operands; it is matched by file name (`/bin/rm`, `rm.exe`). - The sudo bump comes from a sudo/doas wrapper by name (`/usr/bin/sudo`). - Only a tail with `*` or `?` is a glob; `..` resolves to the parent. - `/home` is protected, and MSYS drive paths (`/c`, `/c/Users`) are compared as `c:`, `c:/users`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
Problem
The shell risk gate (
whycodes-command-risk) let destructive commands through as Safe:/bin/rm -rf ~,C:/tools/rm.exe -rf ~/bin/rmmatched nothing)timeout 5 rm -rf /,nice rm -rf ~,env -i rm -rf ~,xargs rm -rf ~,nohup …,stdbuf …,exec …sudo -u root rm -rf /-utaken as the command, then the sudo bump)rm -rf ..,rm -rf foo/../....stripped as a "glob tail")rm -rf /home/../home/)rm -rf /home,/c,/c/Users,/C/Windows(Git Bash spelling ofC:)With the default threshold (Destructive), everything in the Safe/Caution rows ran without a prompt, and the "always refused" tier never fired.
Fix
Segment::command_indexskips assignments, shell keywords and a table of wrappers — sudo, doas, env, command, builtin, exec, nohup, time, nice, ionice, stdbuf, timeout, xargs — with their options, the values of options that take one (sudo -u root,nice -n 10,xargs -I {}),--, and leading operands (timeout's duration). Wrappers nest (nice timeout 5 sudo -u root rm)./bin/rm,rm.exe→rm);args()is the words after the command index (it used to search for the first word equal to the command text).Segment::elevatedreplaces the "any word issudo" check: a sudo/doas wrapper by name (/usr/bin/sudocounts, an argument namedsudodoes not).strip_glob_tailonly strips a tail containing*or?;..resolves lexically to the parent./homejoins the protected roots;msys_drivemaps/c[/rest]toc:[/rest]for the Windows protected list and the bare-drive check.Tests
New in
assess.rs: wrappers and program paths (18 forms, incl. nested and--), the sudo bump through a wrapper,../..//foo/../..//home/..,/homeand MSYS drive roots (and that/c/Users/me/tmpand/cacheare not). All 115 command-risk tests, agent gate/risk tests, clippy, budgets; command-risk line coverage measured locally (only the 2 pre-existing misses).🤖 Generated with Claude Code