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 <noreply@anthropic.com>
This commit is contained in:
parent
6460a0a7c7
commit
5f69bc7c6c
1 changed files with 8 additions and 1 deletions
|
|
@ -81,6 +81,9 @@ var (
|
||||||
// absolutePathPattern matches absolute file paths in commands (Unix and Windows).
|
// absolutePathPattern matches absolute file paths in commands (Unix and Windows).
|
||||||
absolutePathPattern = regexp.MustCompile(`[A-Za-z]:\\[^\\\"']+|/[^\s\"']+`)
|
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
|
// safePaths are kernel pseudo-devices that are always safe to reference in
|
||||||
// commands, regardless of workspace restriction. They contain no user data
|
// commands, regardless of workspace restriction. They contain no user data
|
||||||
// and cannot cause destructive writes.
|
// and cannot cause destructive writes.
|
||||||
|
|
@ -373,7 +376,11 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
|
||||||
return ""
|
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 {
|
for _, raw := range matches {
|
||||||
p, err := filepath.Abs(raw)
|
p, err := filepath.Abs(raw)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue