fix(security): Shell commands auto-executing in 'suggest' mode without permission#197
Merged
Merged
Conversation
Collaborator
|
good find, ty! |
Collaborator
|
Hey! Sorry, this was a docs issue and not unintended behavior. The purpose of "suggest" is to allow the model to read files, but require approval for editing files or running arbitrary (non-read) commands. There's a fair case for adding another approval mode like "always-ask" that is the strictest where even file-read commands like Thanks for the contribution! I'm going to revert this PR now that |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
There's a security vulnerability in the current implementation where shell commands are being executed without requesting user permission even when in 'suggest' mode. According to our documentation:
However, the current implementation in
approvals.tswas auto-approving commands deemed "safe" by theisSafeCommandfunction, bypassing the user permission requirement. This is a security risk as users expect all shell commands to require explicit approval in 'suggest' mode.Solution
This PR fixes the issue by modifying the
canAutoApprovefunction inapprovals.tsto respect the 'suggest' mode policy for all shell commands:Added an early check at the beginning of
canAutoApproveto immediately return{ type: "ask-user" }when the policy issuggest, regardless of whether the command is considered "safe" or not.Added a similar check in the bash command handling section to ensure bash commands also respect the 'suggest' mode.
Updated tests to verify the new behavior, ensuring that all shell commands require approval in 'suggest' mode, while still being auto-approved in 'auto-edit' and 'full-auto' modes when appropriate.
Testing
All tests pass, confirming that the fix works as expected. The updated tests verify that:
This change ensures that the behavior matches what's documented and what users expect, improving security by requiring explicit permission for all shell commands in the default 'suggest' mode.