Skip to content

Commit

Permalink
rework filesystem function
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Jan 11, 2024
1 parent dedd9c6 commit cb5fe1b
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions server/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,20 @@ func (fs FileSystem) newFile(name string) (*File, error) {
return nil, err
}
if !fs.AllowOutsideSymlinks {
if target, err := filepath.EvalSymlinks(absPath); target != "" {
if err != nil {
return nil, err
}
path, err := filepath.Abs(target)
if err != nil {
return nil, err
}
root, err := filepath.Abs(fs.Root)
if err != nil {
return nil, err
}
if !strings.HasPrefix(path, root) {
return nil, os.ErrPermission
}
target, err := filepath.EvalSymlinks(absPath)
if err != nil {
return nil, err
}
path, err := filepath.Abs(target)
if err != nil {
return nil, err
}
root, err := filepath.Abs(fs.Root)
if err != nil {
return nil, err
}
if !strings.HasPrefix(path, root) {
return nil, os.ErrPermission
}
}
return NewFile(absPath, fs.HideDotFiles)
Expand Down

0 comments on commit cb5fe1b

Please sign in to comment.