fix: adjust symlink scope check
parent
71763d08b9
commit
af2c5048d2
|
@ -56,9 +56,8 @@ var resourceGetHandler = withUser(func(w http.ResponseWriter, r *http.Request, d
|
||||||
return errToStatus(err), err
|
return errToStatus(err), err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = checkOutOfScopeSymlink(d, file.Path)
|
if file.IsSymlink && symlinkOutOfScope(d, file) {
|
||||||
if err != nil {
|
return errToStatus(errors.ErrNotExist), errors.ErrNotExist
|
||||||
return errToStatus(err), err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.URL.Query().Get("disk_usage") == "true" {
|
if r.URL.Query().Get("disk_usage") == "true" {
|
||||||
|
@ -357,39 +356,22 @@ func checkParent(src, dst string) error {
|
||||||
|
|
||||||
// Checks if path contains symlink to out-of-scope targets.
|
// Checks if path contains symlink to out-of-scope targets.
|
||||||
// Returns error ErrNotExist if it does.
|
// Returns error ErrNotExist if it does.
|
||||||
func checkOutOfScopeSymlink(d *data, target string) error {
|
func symlinkOutOfScope(d *data, file *files.FileInfo) bool {
|
||||||
lsf, ok := d.user.Fs.(afero.LinkReader)
|
var err error
|
||||||
if !ok {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var parts []string
|
link := ""
|
||||||
for _, part := range strings.Split(target, string(os.PathSeparator)) {
|
if lsf, ok := d.user.Fs.(afero.LinkReader); ok {
|
||||||
if part != "" {
|
if link, err = lsf.ReadlinkIfPossible(file.Path); err != nil {
|
||||||
parts = append(parts, part)
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evalPath := string(os.PathSeparator)
|
if !filepath.IsAbs(link) {
|
||||||
for _, part := range parts {
|
link = filepath.Join(d.user.FullPath(file.Path), link)
|
||||||
evalPath = filepath.Join(evalPath, filepath.Clean(part))
|
|
||||||
symlink, err := lsf.ReadlinkIfPossible(evalPath)
|
|
||||||
if err == nil {
|
|
||||||
parentDir := filepath.Dir(evalPath)
|
|
||||||
var fullLinkTarget string
|
|
||||||
if filepath.IsAbs(symlink) {
|
|
||||||
fullLinkTarget = symlink
|
|
||||||
} else {
|
|
||||||
fullLinkTarget = filepath.Join(d.user.FullPath(parentDir), symlink)
|
|
||||||
}
|
|
||||||
scopedLinkTarget := d.user.FullPath(filepath.Join(parentDir, symlink))
|
|
||||||
if fullLinkTarget != scopedLinkTarget {
|
|
||||||
return errors.ErrNotExist
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
link = filepath.Clean(link)
|
||||||
|
|
||||||
return nil
|
return !strings.HasPrefix(link, d.server.Root)
|
||||||
}
|
}
|
||||||
|
|
||||||
func addVersionSuffix(source string, fs afero.Fs) string {
|
func addVersionSuffix(source string, fs afero.Fs) string {
|
||||||
|
|
Loading…
Reference in New Issue