Skip to content

Commit 62bafde

Browse files
committed
Add input validation and audit logging to shell tool
Validate that the command is not empty before execution, and add debug-level logging for native (non-sandboxed) shell command execution to improve auditability. Fixes #1717 Assisted-By: cagent
1 parent 92d8b18 commit 62bafde

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/tools/builtin/shell.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"errors"
88
"fmt"
9+
"log/slog"
910
"os"
1011
"os/exec"
1112
"runtime"
@@ -137,6 +138,10 @@ func statusToString(status int32) string {
137138
}
138139

139140
func (h *shellHandler) RunShell(ctx context.Context, params RunShellArgs) (*tools.ToolCallResult, error) {
141+
if strings.TrimSpace(params.Cmd) == "" {
142+
return tools.ResultError("Error: empty command"), nil
143+
}
144+
140145
timeout := h.timeout
141146
if params.Timeout > 0 {
142147
timeout = time.Duration(params.Timeout) * time.Second
@@ -152,6 +157,8 @@ func (h *shellHandler) RunShell(ctx context.Context, params RunShellArgs) (*tool
152157
return h.sandbox.runCommand(timeoutCtx, ctx, params.Cmd, cwd, timeout), nil
153158
}
154159

160+
slog.Debug("Executing native shell command", "command", params.Cmd, "cwd", cwd)
161+
155162
return h.runNativeCommand(timeoutCtx, ctx, params.Cmd, cwd, timeout), nil
156163
}
157164

0 commit comments

Comments
 (0)