Skip to content

Commit

Permalink
Prevent following symlinks during extracting normal files
Browse files Browse the repository at this point in the history
This fixes #359, #361, #362.
  • Loading branch information
xanonid committed Sep 26, 2018
1 parent 2ea6ca1 commit b1d4c52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions integration/dockerfiles/Dockerfile_test_replaced_symlinks
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM tenstartups/alpine@sha256:31dc8b12e0f73a1de899146c3663644b7668f8fd198cfe9b266886c9abfa944b
RUN pwd
7 changes: 7 additions & 0 deletions pkg/util/fs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error {
return err
}
}
// Check if something already exists at path (symlinks etc.)
// If so, delete it
if FilepathExists(path) {
if err := os.Remove(path); err != nil {
return errors.Wrapf(err, "error removing %s to make way for new file.", path)
}
}
currFile, err := os.Create(path)
if err != nil {
return err
Expand Down

0 comments on commit b1d4c52

Please sign in to comment.