Files
Soda 2a1f393ad2 fix(skills): enforce portable supporting-file paths (#7743)
Use one slash-delimited path contract for skill authoring endpoints and daemon bundle validation. Cover canonical path handling and all public file-write routes with regression tests.
2026-10-26 13:49:05 +08:00

25 lines
720 B
Go

package skill
import (
"path"
"strings"
)
// IsSafeFilePath reports whether filePath is a canonical, slash-delimited
// supporting-file path accepted consistently by the server and daemon.
func IsSafeFilePath(filePath string) bool {
if filePath == "" || strings.Contains(filePath, "\x00") || strings.HasPrefix(filePath, "/") || strings.Contains(filePath, "\\") {
return false
}
if len(filePath) >= 2 && filePath[1] == ':' && isASCIILetter(filePath[0]) {
return false
}
clean := path.Clean(filePath)
return clean != "." && clean == filePath && clean != ".." && !strings.HasPrefix(clean, "../")
}
func isASCIILetter(value byte) bool {
return value >= 'a' && value <= 'z' || value >= 'A' && value <= 'Z'
}