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 <noreply@anthropic.com>
This commit is contained in:
JexLau 2026-02-18 06:04:56 +08:00
parent ba47892bcf
commit 022af0aa57

View file

@ -188,8 +188,12 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
return "" 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\"']+`) pathPattern := regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
matches := pathPattern.FindAllString(cmd, -1) matches := pathPattern.FindAllString(stripped, -1)
for _, raw := range matches { for _, raw := range matches {
p, err := filepath.Abs(raw) p, err := filepath.Abs(raw)