Skip to content

Commit

Permalink
fixup: validate path in tar header
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Vasek <[email protected]>
  • Loading branch information
matejvasek committed Dec 12, 2023
1 parent f554f97 commit 6d08815
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hack/update-builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,12 @@ func downloadTarball(tarballUrl, destDir string) error {
return fmt.Errorf("cannot read tar header: %w", err)
}

dest := filepath.Join(destDir, filepath.Join(strings.Split(hdr.Name, "/")[1:]...))
n := filepath.Clean(filepath.Join(strings.Split(hdr.Name, "/")[1:]...))

Check failure

Code scanning / CodeQL

Arbitrary file write extracting an archive containing symbolic links High

Unresolved path from an archive header, which may point outside the archive root, is used in
symlink creation
.
if strings.HasPrefix(n, "..") {
return fmt.Errorf("path in tar header escapes")
}
dest := filepath.Join(destDir, n)

switch hdr.Typeflag {
case tar.TypeReg:
var f *os.File
Expand Down

0 comments on commit 6d08815

Please sign in to comment.