@@ -83,6 +83,11 @@ impl ExecuteCommand {
8383
8484 // Check if each command in the pipe chain starts with a safe command
8585 for cmd_args in all_commands {
86+ let cmd_as_str = cmd_args. join ( " " ) ;
87+ if allowed_commands. contains ( & cmd_as_str) {
88+ continue ;
89+ }
90+
8691 match cmd_args. first ( ) {
8792 // Special casing for `find` so that we support most cases while safeguarding
8893 // against unwanted mutations
@@ -97,9 +102,6 @@ impl ExecuteCommand {
97102 return true ;
98103 } ,
99104 Some ( cmd) => {
100- if allowed_commands. contains ( cmd) {
101- continue ;
102- }
103105 // Special casing for `grep`. -P flag for perl regexp has RCE issues, apparently
104106 // should not be supported within grep but is flagged as a possibility since this is perl
105107 // regexp.
@@ -335,4 +337,25 @@ mod tests {
335337 ) ;
336338 }
337339 }
340+
341+ #[ test]
342+ fn test_tool_settings ( ) {
343+ let allowed_commands = [ "git status" , "git diff" ]
344+ . into_iter ( )
345+ . map ( |s| s. to_string ( ) )
346+ . collect :: < Vec < _ > > ( ) ;
347+ let execute_cmd = ExecuteCommand {
348+ command : "git status" . to_string ( ) ,
349+ summary : None ,
350+ } ;
351+ let requires_acceptance = execute_cmd. requires_acceptance ( Some ( & allowed_commands) , false ) ;
352+ assert ! ( !requires_acceptance) ;
353+
354+ let execute_cmd = ExecuteCommand {
355+ command : "git commit" . to_string ( ) ,
356+ summary : None ,
357+ } ;
358+ let requires_acceptance = execute_cmd. requires_acceptance ( Some ( & allowed_commands) , false ) ;
359+ assert ! ( requires_acceptance) ;
360+ }
338361}
0 commit comments