Potential fix for code scanning alert no. 69: Arbitrary file access during archive extraction ("Zip Slip")
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> Signed-off-by: Rick <1450685+LinuxSuRen@users.noreply.github.com>
This commit is contained in:
parent
0d30d5e6cc
commit
46722dde96
|
@ -27,6 +27,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DownloadSwaggerData(output string, dw downloader.PlatformAwareOCIDownloader) (err error) {
|
func DownloadSwaggerData(output string, dw downloader.PlatformAwareOCIDownloader) (err error) {
|
||||||
|
@ -106,6 +107,12 @@ func decompressData(dataFile string) (err error) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ensure the file path does not contain directory traversal sequences
|
||||||
|
if strings.Contains(header.Name, "..") {
|
||||||
|
fmt.Printf("Skipping entry with unsafe path: %s\n", header.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
destPath := filepath.Join(filepath.Dir(dataFile), filepath.Base(header.Name))
|
destPath := filepath.Join(filepath.Dir(dataFile), filepath.Base(header.Name))
|
||||||
|
|
||||||
switch header.Typeflag {
|
switch header.Typeflag {
|
||||||
|
|
Loading…
Reference in New Issue