fix(permission): scope "always" approval to the command that was shown - #40152
Open
0xSemizzz wants to merge 1 commit into
Open
fix(permission): scope "always" approval to the command that was shown#401520xSemizzz wants to merge 1 commit into
0xSemizzz wants to merge 1 commit into
Conversation
`collect()` accumulated one arity-widened `always` pattern per command node into a single set, and `Permission.reply` installs an allow rule for every entry of that set when the user answers "always". For a compound command this turns one user decision into several grants: approving `git status && rm -rf ~` installs both `git status *` and `rm *`, and `rm *` matches `rm -rf /` on the next turn. Keep the widened prefix only when the request covers exactly one command. Otherwise fall back to the literal command strings, so "always" grants exactly the commands that were displayed in the prompt.
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.
collect()accumulated one arity-widenedalwayspattern per command node into a single set, andPermission.replyinstalls an allow rule for every entry of that set when the user answers "always".For a compound command this turns one user decision into several grants: approving
git status && rm -rf ~installs bothgit status *andrm *, andrm *matchesrm -rf /on the next turn.Keep the widened prefix only when the request covers exactly one command. Otherwise fall back to the literal command strings, so "always" grants exactly the commands that were displayed in the prompt.
Issue for this PR
Closes #40158
Type of change
What does this PR do?
scan.alwaysintool/shell.tsis aSetthat gets one entry per command node found in the parsed command.ask()sends the whole set as the request'salwayslist, andpermission/index.tsloops that list on an "always" reply, pushing an allow rule for each entry.So the widening is per command but the approval is per request. With one command that is fine: you approve
git status, you getgit status *. With two it is wrong, because you see one prompt, click once, and get a rule for each command in it. Thermcase is the bad one, sinceBashAritygivesrman arity of 1, sorm -rf ~widens torm *, which then matches any futurerm.The fix keeps the existing widening when
found.length === 1and otherwise uses the literal command text. Re-running the same compound command still matches and stays allowed.rm -rf /does not matchrm -rf tmpand still prompts.How did you verify your code works?
Two tests in
packages/opencode/test/tool/shell.test.ts. One assertsgit statusstill widens togit status *. The other assertsgit status && rm -rf tmpyields neitherrm *norgit status *, but does yield both literals. Both use the existingcapture(requests, err)helper so the command never actually executes.cd packages/opencode && bun test test/tool/shell.test.tsScreenshots / recordings
N/A, no UI change.
Checklist