fix(shell): close external_directory gaps in the command path scan - #40153
Open
0xSemizzz wants to merge 1 commit into
Open
fix(shell): close external_directory gaps in the command path scan#401530xSemizzz wants to merge 1 commit into
0xSemizzz wants to merge 1 commit into
Conversation
`external_directory` is documented as firing whenever a tool touches paths
outside the project directory, and the file tools honour that for every call.
The shell tool only honoured it for a small allowlist of command names, and
dropped any argument containing a `$`.
Two gaps followed:
tee ~/.ssh/authorized_keys -> `tee` was not scanned, so no prompt
rm $HOME/.ssh/id_rsa -> `rm` is scanned, but `dynamic()` discarded
the argument before it could be resolved
Add the common file readers and writers that take their target as a plain
positional argument, and expand `$HOME`/`$PWD` for POSIX shells the way
`expand()` already does for PowerShell. Anything still unresolvable after
expansion continues to fall through `dynamic()` untouched.
Redirection targets (`echo x > /etc/foo`) are still not scanned; `parts()`
skips redirection nodes. Left for a follow-up.
Contributor
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
The docs say
external_directoryfires whenever a tool touches paths outside the project directory. The file tools do that for every call. The shell tool only did it for a short allowlist of command names, and threw away any argument containing a$.So
tee ~/.ssh/authorized_keysnever prompted, becauseteewas not scanned. Andrm $HOME/.ssh/id_rcause althoughrmis scanned,dynamic()` discarded the argument before it could be resolved.Add the common readers and writers that take their target as a plain positional argument, and expand
hells the wayexpand()` already does for PowerShell.Issue for this PR
Closes #40159
Type of change
What does this PR do?
Two changes in
tool/shell.ts.FILESgains the file commands that were missing:tee,dd,ln,rsync,shred,split,truncate,install,unlinkon the write side, andhead,tail,sed,sort,wc,diff,cmp,less,moreon the readside. Only commands whose target is a plain positional argument, since that is what
pathArgs()can aready inside the project resolves and is skipped as before, so this only prompts for paths thatgenuinely leave the project.argPath()now runs POSIX arguments through a newposixExpand()that substitutes$HOMEand$PWD(both$VARand${VAR}forms) beforedynamic()sees them. Only those two, because they are the only ones resolvable without running the shell.$OTHER,$(cmd), and backticks still fall throughdynamic()and get skipped exactly as they do today.$HOMEBREWdeliberately does not match, because the pattern requires a/or end of string after the name.Redirection targets such as
echo x > /etc/fooare still not scanned, becauseparts()skips redirection nodes and handling them means walkingredirected_statementchildren. That is a bigger change and worth a follow-up.How did you verify your code works?
Two tests in
packages/opencode/test/tool/shell.test.ts, POSIX only.echo hi | tee /etc/...expects anexternal_directoryrequest for/etc/*, andrm $HOME/.ssh/...expects one for<home>/.ssh/*. Both stop at the permissioncall so nothing runs.I also ran
posixExpandagainst$HOME/x,${HOME}/x,"$HOME/x",$PWD/../x,$HOMEBREW/x,$OTHER/x,$(whoami)/x,~/x, and a plain relative path, to confirm the first four expand and the rest stay dynamic.cd packages/opencode && bun test test/tool/shell.test.tsScreenshots / recordings
N/A, no UI change.
Checklist