Skip to content

Commit

Permalink
Merge pull request #50 from whickman/wh/handle-bad-file-path
Browse files Browse the repository at this point in the history
Handle filenames with leading periods correctly
  • Loading branch information
mcuadros authored Jan 14, 2018
2 parents 053dbd0 + e608ed0 commit e940f8b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion helper/chroot/chroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions helper/chroot/chroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down

0 comments on commit e940f8b

Please sign in to comment.