Skip to content

Commit 8cde47a

Browse files
committed
chroot: allow Symlinks cross boundary
1 parent 45b3d23 commit 8cde47a

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

helper/chroot/chroot.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,6 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
169169
target = filepath.Clean(filepath.FromSlash(target))
170170
}
171171

172-
if fs.isTargetOutBounders(link, target) {
173-
return billy.ErrCrossedBoundary
174-
}
175-
176172
link, err := fs.underlyingPath(link)
177173
if err != nil {
178174
return err
@@ -181,17 +177,6 @@ func (fs *ChrootHelper) Symlink(target, link string) error {
181177
return fs.underlying.(billy.Symlink).Symlink(target, link)
182178
}
183179

184-
func (fs *ChrootHelper) isTargetOutBounders(link, target string) bool {
185-
fulllink := fs.Join(fs.base, link)
186-
fullpath := fs.Join(filepath.Dir(fulllink), target)
187-
target, err := filepath.Rel(fs.base, fullpath)
188-
if err != nil {
189-
return true
190-
}
191-
192-
return isCrossBoundaries(target)
193-
}
194-
195180
func (fs *ChrootHelper) Readlink(link string) (string, error) {
196181
fullpath, err := fs.underlyingPath(link)
197182
if err != nil {

test/fs.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ func (s *FilesystemSuite) TestSymlinkWithChrootBasic(c *C) {
104104

105105
func (s *FilesystemSuite) TestSymlinkWithChrootCrossBounders(c *C) {
106106
qux, _ := s.FS.Chroot("/qux")
107-
err := qux.(Filesystem).Symlink("../../file", "qux/link")
108-
c.Assert(err, Equals, ErrCrossedBoundary)
107+
util.WriteFile(s.FS, "file", []byte("foo"), customMode)
108+
109+
err := qux.Symlink("../../file", "qux/link")
110+
c.Assert(err, Equals, nil)
111+
112+
fi, err := qux.Stat("qux/link")
113+
c.Assert(fi, NotNil)
114+
c.Assert(err, Equals, nil)
109115
}
110116

111117
func (s *FilesystemSuite) TestReadDirWithLink(c *C) {

0 commit comments

Comments
 (0)