Skip to content

Commit

Permalink
Fix code scanning alert no. 2: Arbitrary file access during archive e…
Browse files Browse the repository at this point in the history
…xtraction ("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>
  • Loading branch information
1 parent f538704 commit 9f653a2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9f653a2

Please sign in to comment.