Initial commit: DSH Web Manager
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func toHostPath(containerRoot, hostRoot, containerPath string) (string, error) {
|
||||
if !filepath.IsAbs(containerRoot) || !filepath.IsAbs(hostRoot) || !filepath.IsAbs(containerPath) {
|
||||
return "", errors.New("absolute storage paths required")
|
||||
}
|
||||
rel, err := filepath.Rel(containerRoot, containerPath)
|
||||
if err != nil || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
return "", errors.New("storage path escapes root")
|
||||
}
|
||||
return filepath.Join(hostRoot, rel), nil
|
||||
}
|
||||
Reference in New Issue
Block a user