diff --git a/pkg/apispec/remote_swagger.go b/pkg/apispec/remote_swagger.go index 3a0be27..4504e78 100644 --- a/pkg/apispec/remote_swagger.go +++ b/pkg/apispec/remote_swagger.go @@ -27,6 +27,7 @@ import ( "net/http" "os" "path/filepath" + "strings" ) func DownloadSwaggerData(output string, dw downloader.PlatformAwareOCIDownloader) (err error) { @@ -106,6 +107,12 @@ func decompressData(dataFile string) (err error) { 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)) switch header.Typeflag {