Skip to content

Commit 36d14cf

Browse files
committed
chore(cli): fix zip-slip vulnerability
1 parent 65a4ea8 commit 36d14cf

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

  • cli/toob-cli/internal/registry

cli/toob-cli/internal/registry/zip.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ func downloadAndExtractZip(url string, targetDir string) error {
4848
relPath := filepath.FromSlash(parts[1])
4949
destPath := filepath.Join(targetDir, relPath)
5050

51+
// Zip-Slip protection
52+
cleanDest := filepath.Clean(destPath)
53+
cleanTarget := filepath.Clean(targetDir) + string(os.PathSeparator)
54+
if !strings.HasPrefix(cleanDest, cleanTarget) {
55+
return fmt.Errorf("illegal path (zip-slip): %s", destPath)
56+
}
57+
5158
if f.FileInfo().IsDir() {
5259
os.MkdirAll(destPath, 0o755)
5360
continue

0 commit comments

Comments
 (0)