diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index 2ea58b2599..b8a811d038 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -59,7 +59,7 @@ var ( regexp.MustCompile(`\bchown\b`), regexp.MustCompile(`\bpkill\b`), regexp.MustCompile(`\bkillall\b`), - regexp.MustCompile(`\bkill\s+-[9]\b`), + regexp.MustCompile(`\bkill\b`), regexp.MustCompile(`\bcurl\b.*\|\s*(sh|bash)`), regexp.MustCompile(`\bwget\b.*\|\s*(sh|bash)`), regexp.MustCompile(`\bnpm\s+install\s+-g\b`), diff --git a/pkg/tools/shell_test.go b/pkg/tools/shell_test.go index a6abca8ea8..ff9ea4a152 100644 --- a/pkg/tools/shell_test.go +++ b/pkg/tools/shell_test.go @@ -151,6 +151,26 @@ func TestShellTool_DangerousCommand(t *testing.T) { } } +func TestShellTool_DangerousCommand_KillBlocked(t *testing.T) { + tool, err := NewExecTool("", false) + if err != nil { + t.Errorf("unable to configure exec tool: %s", err) + } + + ctx := context.Background() + args := map[string]any{ + "command": "kill 12345", + } + + result := tool.Execute(ctx, args) + if !result.IsError { + t.Errorf("Expected kill command to be blocked") + } + if !strings.Contains(result.ForLLM, "blocked") && !strings.Contains(result.ForUser, "blocked") { + t.Errorf("Expected blocked message, got ForLLM: %s, ForUser: %s", result.ForLLM, result.ForUser) + } +} + // TestShellTool_MissingCommand verifies error handling for missing command func TestShellTool_MissingCommand(t *testing.T) { tool, err := NewExecTool("", false)