Skip to content

Commit

Permalink
Protect Untar function from a zip slip. (#2459)
Browse files Browse the repository at this point in the history
  • Loading branch information
ptodev authored Jan 22, 2025
1 parent 51ed068 commit 7dcb41a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/util/untar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
)

// Untar untars a tarball to the provided destination path.
Expand All @@ -31,6 +32,13 @@ func Untar(tarPath string, destPath string) error {
return err
}

// Protect from a zip slip.
// https://security.snyk.io/research/zip-slip-vulnerability
if strings.Contains(header.Name, `../`) ||
strings.Contains(header.Name, `..\`) {
return fmt.Errorf("tar: invalid file path: %s", header.Name)
}

fullPath := filepath.Join(destPath, header.Name)
switch header.Typeflag {
case tar.TypeDir:
Expand Down

0 comments on commit 7dcb41a

Please sign in to comment.