From 022af0aa577f34206d1abc99e055aec51c3baa75 Mon Sep 17 00:00:00 2001 From: JexLau Date: Wed, 18 Feb 2026 06:04:56 +0800 Subject: [PATCH] fix: exec tool should not treat URLs as file paths The guardCommand path check regex misidentifies URL components as filesystem paths (e.g. `//example.com` from `https://example.com`), causing commands like `curl https://...` to be blocked with "path outside working dir". Strip URLs from the command string before running path checks. Fixes #386 Co-Authored-By: Claude Opus 4.6 --- pkg/tools/shell.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index 713850f97..c41ab3bad 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -188,8 +188,12 @@ func (t *ExecTool) guardCommand(command, cwd string) string { return "" } + // Strip URLs before path checking so they don't get misidentified as file paths + urlPattern := regexp.MustCompile(`[a-zA-Z][a-zA-Z0-9+.-]*://[^\s\"']+`) + stripped := urlPattern.ReplaceAllString(cmd, "") + pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`) - matches := pathPattern.FindAllString(cmd, -1) + matches := pathPattern.FindAllString(stripped, -1) for _, raw := range matches { p, err := filepath.Abs(raw)