Consolidated a bunch of reused code to agents
This commit is contained in:
23
pkg/agents/console-new/util.go
Normal file
23
pkg/agents/console-new/util.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package console_new
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func SafeJoinPath(tempDir, fileName string) (string, error) {
|
||||
// Clean both paths
|
||||
tempDir = filepath.Clean(tempDir)
|
||||
fileName = filepath.Clean(fileName)
|
||||
|
||||
// Join paths and clean result
|
||||
fullPath := filepath.Clean(filepath.Join(tempDir, fileName))
|
||||
|
||||
// Verify the path is still within tempDir
|
||||
if !strings.HasPrefix(fullPath, tempDir+string(filepath.Separator)) {
|
||||
return "", fmt.Errorf("invalid path")
|
||||
}
|
||||
|
||||
return fullPath, nil
|
||||
}
|
Reference in New Issue
Block a user