From 5f69bc7c6cbb5c6d8b2775dcfa3b83d447d18a4f Mon Sep 17 00:00:00 2001 From: hobostay Date: Thu, 12 Mar 2026 16:43:54 +0800 Subject: [PATCH] fix: prevent safety guard from blocking commands containing URLs The absolutePathPattern regex in the workspace safety check was matching URL path components (e.g., //github.com) as absolute file paths, causing commands like "agent-browser open https://github.com" to be incorrectly blocked. This fix: - Adds a urlPattern to match HTTP(S) URLs - Strips URLs from commands before path safety checks - Preserves all existing safety checks for actual file paths Fixes #1203 Co-Authored-By: Claude Opus 4.6 --- pkg/tools/shell.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/tools/shell.go b/pkg/tools/shell.go index 67e2ad257..1bb5f9228 100644 --- a/pkg/tools/shell.go +++ b/pkg/tools/shell.go @@ -81,6 +81,9 @@ var ( // absolutePathPattern matches absolute file paths in commands (Unix and Windows). absolutePathPattern = regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`) + // urlPattern matches HTTP(S) URLs to exclude them from path safety checks. + urlPattern = regexp.MustCompile(`https?://[^\s\"']+`) + // safePaths are kernel pseudo-devices that are always safe to reference in // commands, regardless of workspace restriction. They contain no user data // and cannot cause destructive writes. @@ -373,7 +376,11 @@ func (t *ExecTool) guardCommand(command, cwd string) string { return "" } - matches := absolutePathPattern.FindAllString(cmd, -1) + // Remove URLs from the command before matching paths to avoid false positives. + // For example, "agent-browser open https://github.com" should not trigger + // a path safety check on the URL's path component. + cmdWithoutURLs := urlPattern.ReplaceAllString(cmd, "") + matches := absolutePathPattern.FindAllString(cmdWithoutURLs, -1) for _, raw := range matches { p, err := filepath.Abs(raw)