Skip to content

Commit 50e1e7b

Browse files
Added check condition in pkg/dependencies/downloader.go (#5394)
2 parents fc84605 + 4e76995 commit 50e1e7b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/dependencies/downloader.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ func extractBinary(body []byte, binaryName string, targetDir string) error {
116116
continue // we only want the main executable
117117
}
118118

119+
// Sanitize file name to prevent path traversal (Zip Slip).
120+
// See: https://snyk.io/research/zip-slip-vulnerability
121+
destPath := filepath.Join(targetDir, file.Name)
122+
if !strings.HasPrefix(destPath, filepath.Clean(targetDir)+string(os.PathSeparator)) {
123+
return fmt.Errorf("malicious archive entry, path traversal attempt: %s", file.Name)
124+
}
125+
119126
cleanFileName := filepath.Base(file.Name)
120127
extractedTempPath = filepath.Join(tempDir, cleanFileName)
121128
extractedFileName = file.Name

0 commit comments

Comments
 (0)