-
Notifications
You must be signed in to change notification settings - Fork 295
feat: Allow readonly find -exec
commands without permission prompt
#2829
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ions - Refined behavior to allow readonly `-exec` or `-execdir` commands by checking against `READONLY_COMMANDS`. - Introduced additional test cases to confirm expected handling of readonly vs. mutable operations. - Adjusted existing test formatting for consistency.
- Introduced `DANGEROUS_MID_PATTERNS` to identify unsafe patterns when they appear mid-argument. - Added logic to detect and handle these cases, ensuring stricter command validation.
- Updated logic to handle multiple `-exec` arguments, requiring confirmation if any are non-readonly. - Adjusted return behavior to reflect accurate validation outcomes. - Added test cases for mixed and readonly `-exec` scenarios.
find -exec
readonly commands without permission promptfind -exec
commands without permission prompt
…le` helper - Unified logic for detecting dangerous patterns into a single function, reducing code complexity. - Simplified safety checks by removing redundant mid-pattern logic. - Added comprehensive test cases to validate `contains_in_middle` functionality.
a77ac45
to
78f98b4
Compare
.iter() | ||
.any(|arg| DANGEROUS_PATTERNS.iter().any(|p| arg.contains(p))) | ||
.any(|p| contains_but_not_ends_with(&self.command, p)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If DANGEROUS_PATTERNS only appears at the end, it is no longer treated as a dangerous command.
Because these commands cannot appear at the end, or if they do, they are not dangerous commands (e.g., ;
).
…_ends_with` - Improved function to better reflect its purpose of excluding patterns at the end of a string. - Adjusted logic to simplify checks and enhance clarity. - Updated test cases to align with renamed function and new scenarios.
e04bb36
to
6dc7a05
Compare
}) => | ||
{ | ||
return true; | ||
}, | ||
// Check -exec commands separately to allow readonly commands |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- when using
find + -exec
, if the command following exec is readonly, no permission prompt is required. - this also works correctly when multiple
-exec
clauses are present.
Summary
When using the Amazon Q Developer CLI, the LLM Agent often execute readonly file exploration commands such as:
Even with the agent config
toolSettings.execute_bash.allowReadonly = true
, the CLI still asks user for permission when executing this type of command. (related documents)Root Cause
find + -exec
is currently treated as permission-required commands.;
are treated as dangerous and require permission for security reasons.Changes
find -exec
handlingfind
+-exec
, if the command following exec is readonly, no permission prompt is required.;
) handling;
is only considered dangerous when it appears in the middle of a command.;
only appears at the end, it is no longer treated as a dangerous command.Related Issue
#1917
Review Notes