fix(exec): move boundary check after URL filtering

This commit is contained in:
李龙 0668001470 2026-03-16 08:49:01 +08:00
parent 8a8554c189
commit 3981a1a58e

View file

@ -384,15 +384,13 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
matchIndices := absolutePathPattern.FindAllStringIndex(cmd, -1) matchIndices := absolutePathPattern.FindAllStringIndex(cmd, -1)
for _, loc := range matchIndices { for _, loc := range matchIndices {
if !isPathBoundary(cmd, loc[0]) {
continue
}
raw := cmd[loc[0]:loc[1]] raw := cmd[loc[0]:loc[1]]
// Skip URL path components that look like they're from web URLs. // Skip URL path components that look like they're from web URLs.
// When a URL like "https://github.com" is parsed, the regex captures // When a URL like "https://github.com" is parsed, the regex captures
// "//github.com" as a match (the path portion after "https:"). // "//github.com" as a match (the path portion after "https:").
// Use the exact match position (loc[0]) so that duplicate //path substrings
// in the same command are each evaluated at their own position.
if strings.HasPrefix(raw, "//") && loc[0] > 0 { if strings.HasPrefix(raw, "//") && loc[0] > 0 {
before := cmd[:loc[0]] before := cmd[:loc[0]]
isWebURL := false isWebURL := false
@ -409,6 +407,10 @@ func (t *ExecTool) guardCommand(command, cwd string) string {
} }
} }
if !isPathBoundary(cmd, loc[0]) {
continue
}
p, err := filepath.Abs(raw) p, err := filepath.Abs(raw)
if err != nil { if err != nil {
continue continue