mirror of
https://github.com/coreybutler/nvm-windows.git
synced 2026-01-14 07:03:17 +08:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user