Skip to content

Commit 69643bd

Browse files
committed
toolbox: fix codeql go/zipslip
Updates the `archiveRead` function in the `toolbox/hgfs/archive.go` file. The change adds validation to prevent directory traversal attacks. Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
1 parent 410e92e commit 69643bd

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

toolbox/hgfs/archive.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ func archiveRead(u *url.URL, tr *tar.Reader) error {
238238
return err
239239
}
240240

241+
// validate to prevent directory traversal
242+
if strings.Contains(header.Name, "..") {
243+
log.Printf("skipping invalid entry with '..' in name: %s", header.Name)
244+
continue
245+
}
246+
241247
name := filepath.Join(u.Path, header.Name)
242248
mode := os.FileMode(header.Mode)
243249

0 commit comments

Comments
 (0)