diff --git a/helper/chroot/chroot.go b/helper/chroot/chroot.go index 71524ec..e3e5a6d 100644 --- a/helper/chroot/chroot.go +++ b/helper/chroot/chroot.go @@ -37,7 +37,7 @@ func isCrossBoundaries(path string) bool { path = filepath.ToSlash(path) path = filepath.Clean(path) - return strings.HasPrefix(path, "..") + return strings.HasPrefix(path, ".."+string(filepath.Separator)) } func (fs *ChrootHelper) Create(filename string) (billy.File, error) { diff --git a/helper/chroot/chroot_test.go b/helper/chroot/chroot_test.go index 43bd6e6..580347a 100644 --- a/helper/chroot/chroot_test.go +++ b/helper/chroot/chroot_test.go @@ -37,6 +37,15 @@ func (s *ChrootSuite) TestCreateErrCrossedBoundary(c *C) { c.Assert(err, Equals, billy.ErrCrossedBoundary) } +func (s *ChrootSuite) TestLeadingPeriodsPathNotCrossedBoundary(c *C) { + m := &test.BasicMock{} + + fs := New(m, "/foo") + f, err := fs.Create("..foo") + c.Assert(err, IsNil) + c.Assert(f.Name(), Equals, "..foo") +} + func (s *ChrootSuite) TestOpen(c *C) { m := &test.BasicMock{}