Fix code scanning alert no. 2: Arbitrary file access during archive extraction ("Zip Slip")

Prevent zip extraction from processing arbitrary files.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
Corey Butler
2025-01-03 21:25:16 -06:00
committed by GitHub
parent f538704ab5
commit 9f653a2ce6

View File

@@ -845,6 +845,11 @@ func unzip(src string, dest string) error {
// Build the path for each file in the destination directory
fpath := filepath.Join(dest, f.Name)
// Validate the file path to prevent directory traversal
if strings.Contains(f.Name, "..") {
return fmt.Errorf("invalid file path: %s", f.Name)
}
// Check if the file is a directory
if f.FileInfo().IsDir() {
// Create directory if it doesn't exist