Skip to content

Commit

Permalink
test revert
Browse files Browse the repository at this point in the history
  • Loading branch information
albertodonato committed Jan 11, 2024
1 parent cb5fe1b commit 88f3a6c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
26 changes: 12 additions & 14 deletions server/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,18 @@ func (fs FileSystem) newFile(name string) (*File, error) {
return nil, err
}
if !fs.AllowOutsideSymlinks {
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
if target, _ := os.Readlink(absPath); target != "" {
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
4 changes: 2 additions & 2 deletions server/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *FileSystemTestSuite) TestNoLookupWithHTMLSuffix() {
func (s *FileSystemTestSuite) TestNoOutsideSymlink() {
s.WriteFile("foo", "content")
root := s.Mkdir("root")
s.Symlink("../foo", "root/foo-link")
s.Symlink("foo", "root/foo-link")
fs := server.FileSystem{Root: root}
file, err := fs.Open("/foo-link")
s.IsType(os.ErrPermission, err)
Expand All @@ -113,7 +113,7 @@ func (s *FileSystemTestSuite) TestNoOutsideSymlink() {
func (s *FileSystemTestSuite) TestOutsideSymlinks() {
s.WriteFile("foo", "content")
root := s.Mkdir("root")
s.Symlink("../foo", "root/foo-link")
s.Symlink("foo", "root/foo-link")
fs := server.FileSystem{Root: root, AllowOutsideSymlinks: true}
file, err := fs.Open("/foo-link")
s.Nil(err)
Expand Down
2 changes: 1 addition & 1 deletion server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (s *StaticServerTestSuite) TestSetupServerSpecifyAllowOutsideSymlinks() {
content := "some content"
s.WriteFile("outside.txt", content)
subdir := s.Mkdir("sub")
s.Symlink("../outside.txt", "sub/test.txt")
s.Symlink("outside.txt", "sub/test.txt")
serv, err := server.NewStaticServer(server.StaticServerConfig{
Dir: subdir,
AllowOutsideSymlinks: true,
Expand Down
3 changes: 2 additions & 1 deletion testhelpers/tempdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func (s *TempDirTestSuite) Mkdir(name string) string {
// Symlink creates a symbolic link to oldname returning the absolute path of
// the new name. Both paths are relative to the tempdir path.
func (s *TempDirTestSuite) Symlink(oldname, newname string) string {
oldPath := s.absPath(oldname)
newPath := s.absPath(newname)
err := os.Symlink(oldname, newPath)
err := os.Symlink(oldPath, newPath)
s.Nil(err)
return newPath
}
Expand Down

0 comments on commit 88f3a6c

Please sign in to comment.