Skip to content

Commit

Permalink
Merge pull request #38 from mcuadros/cross
Browse files Browse the repository at this point in the history
chroot: allow Symlinks cross boundary
  • Loading branch information
mcuadros authored Jun 26, 2017
2 parents c74cbe6 + 8cde47a commit 1801347
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
15 changes: 0 additions & 15 deletions helper/chroot/chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,6 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
target = filepath.Clean(filepath.FromSlash(target))
}

if fs.isTargetOutBounders(link, target) {
return billy.ErrCrossedBoundary
}

link, err := fs.underlyingPath(link)
if err != nil {
return err
Expand All @@ -181,17 +177,6 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
return fs.underlying.(billy.Symlink).Symlink(target, link)
}

func (fs *ChrootHelper) isTargetOutBounders(link, target string) bool {
fulllink := fs.Join(fs.base, link)
fullpath := fs.Join(filepath.Dir(fulllink), target)
target, err := filepath.Rel(fs.base, fullpath)
if err != nil {
return true
}

return isCrossBoundaries(target)
}

func (fs *ChrootHelper) Readlink(link string) (string, error) {
fullpath, err := fs.underlyingPath(link)
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions test/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,14 @@ func (s *FilesystemSuite) TestSymlinkWithChrootBasic(c *C) {

func (s *FilesystemSuite) TestSymlinkWithChrootCrossBounders(c *C) {
qux, _ := s.FS.Chroot("/qux")
err := qux.(Filesystem).Symlink("../../file", "qux/link")
c.Assert(err, Equals, ErrCrossedBoundary)
util.WriteFile(s.FS, "file", []byte("foo"), customMode)

err := qux.Symlink("../../file", "qux/link")
c.Assert(err, Equals, nil)

fi, err := qux.Stat("qux/link")
c.Assert(fi, NotNil)
c.Assert(err, Equals, nil)
}

func (s *FilesystemSuite) TestReadDirWithLink(c *C) {
Expand Down

0 comments on commit 1801347

Please sign in to comment.