diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e62ec92..9c1c180 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,4 +62,4 @@ jobs: - name: Test run: | - go test ./... + go test -v ./... diff --git a/server/filesystem.go b/server/filesystem.go index e8720f2..def32a3 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -71,21 +71,25 @@ 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 - } + path, err := filepath.EvalSymlinks(absPath) + if err != nil { + return nil, err + } + path, err = filepath.Abs(path) + if err != nil { + return nil, err + } + root, err := filepath.EvalSymlinks(fs.Root) + if err != nil { + return nil, err + } + root, err = filepath.Abs(root) + if err != nil { + return nil, err + } + fmt.Println("-->", absPath, path, root, strings.HasPrefix(path, root)) + if !strings.HasPrefix(path, root) { + return nil, os.ErrPermission } } return NewFile(absPath, fs.HideDotFiles) diff --git a/testhelpers/tempdir.go b/testhelpers/tempdir.go index c9c66f3..b63bc6c 100644 --- a/testhelpers/tempdir.go +++ b/testhelpers/tempdir.go @@ -1,6 +1,7 @@ package testhelpers import ( + "fmt" "os" "path/filepath" @@ -56,6 +57,7 @@ func (s *TempDirTestSuite) Mkdir(name string) string { // the new name. Both paths are relative to the tempdir path. func (s *TempDirTestSuite) Symlink(oldname, newname string) string { newPath := s.absPath(newname) + fmt.Println(">>", oldname, newname, newPath) err := os.Symlink(oldname, newPath) s.Nil(err) return newPath