From 89085d9edf6c280c4e094521dc4e0fcb29e6dc18 Mon Sep 17 00:00:00 2001 From: yuxuan-7814 Date: Fri, 8 May 2026 15:57:18 +0800 Subject: [PATCH] fix: resolve relative paths correctly in exec tool safety guard Previously, relative paths in shell commands were resolved using the process's current working directory instead of the command's intended working directory. This caused legitimate relative paths (e.g., skills/file.md) to be evaluated as absolute paths from the process root, triggering false-positive safety blocks. The guardCommand method now correctly distinguishes absolute and relative paths: - Absolute paths are used as-is (cleaned) - Relative paths are joined with the command's cwd before validation This ensures relative paths are resolved relative to the intended working directory. Closes #2749 --- pkg/tools/shell.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index a570ac9ec..ac9c5bf2a 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -1094,9 +1094,15 @@ func (t *ExecTool) guardCommand(command, cwd string) string { } } - p, err := filepath.Abs(raw) - if err != nil { - continue + // Resolve the path correctly based on cwd: + // - Absolute paths: use as-is (cleaned) + // - Relative paths: join with cwd to resolve correctly + var p string + if filepath.IsAbs(raw) { + p = filepath.Clean(raw) + } else { + p = filepath.Join(cwdPath, raw) + p = filepath.Clean(p) } if safePaths[p] {