Merge pull request #1069 from RooVetGit/auto_approve_wildcard

Allow setting a wildcard for auto-approve commands
This commit is contained in:
Matt Rubens 2025-02-19 12:21:24 -05:00 committed by GitHub
commit ebfe57b1ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 20 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
"roo-cline": patch
---
Allow setting a wildcard for auto-approve commands

View file

@ -401,7 +401,7 @@ const SettingsView = ({ onDone }: SettingsViewProps) => {
color: "var(--vscode-descriptionForeground)",
}}>
Command prefixes that can be auto-executed when "Always approve execute operations"
is enabled.
is enabled. Add * to allow all commands (use with caution).
</p>
<div style={{ display: "flex", gap: "5px", marginTop: "10px" }}>

View file

@ -106,5 +106,16 @@ describe("Command Validation", () => {
expect(validateCommand("", allowedCommands)).toBe(true)
expect(validateCommand(" ", allowedCommands)).toBe(true)
})
it("allows all commands when wildcard is present", () => {
const wildcardAllowedCommands = ["*"]
// Should allow any command, including dangerous ones
expect(validateCommand("rm -rf /", wildcardAllowedCommands)).toBe(true)
expect(validateCommand("dangerous-command", wildcardAllowedCommands)).toBe(true)
expect(validateCommand("npm test && rm -rf /", wildcardAllowedCommands)).toBe(true)
// Should even allow subshell commands that are normally blocked
expect(validateCommand("npm test $(echo dangerous)", wildcardAllowedCommands)).toBe(true)
expect(validateCommand("npm test `rm -rf /`", wildcardAllowedCommands)).toBe(true)
})
})
})

View file

@ -104,6 +104,9 @@ export function isAllowedSingleCommand(command: string, allowedCommands: string[
export function validateCommand(command: string, allowedCommands: string[]): boolean {
if (!command?.trim()) return true
// If '*' is in allowed commands, everything is allowed
if (allowedCommands?.includes("*")) return true
// Block subshell execution attempts
if (command.includes("$(") || command.includes("`")) {
return false