v0.0.5: context compaction, minimal config, retry/search/code symbols/diff/status/test commands
This commit is contained in:
+19
-2
@@ -1,7 +1,9 @@
|
||||
package tools
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func resolvePath(baseDir, path string) (string, error) {
|
||||
@@ -9,7 +11,22 @@ func resolvePath(baseDir, path string) (string, error) {
|
||||
path = "."
|
||||
}
|
||||
if filepath.IsAbs(path) {
|
||||
return filepath.Clean(path), nil
|
||||
return "", fmt.Errorf("absolute paths are not allowed; use a path relative to the project directory")
|
||||
}
|
||||
return filepath.Abs(filepath.Join(baseDir, path))
|
||||
resolved := filepath.Clean(filepath.Join(baseDir, path))
|
||||
if !isWithinDir(resolved, baseDir) {
|
||||
return "", fmt.Errorf("path escapes the project directory: %s", path)
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
|
||||
func isWithinDir(path, dir string) bool {
|
||||
rel, err := filepath.Rel(dir, path)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user