Skip to content

Commit 46722dd

Browse files
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 <[email protected]>
1 parent 0d30d5e commit 46722dd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/apispec/remote_swagger.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"net/http"
2828
"os"
2929
"path/filepath"
30+
"strings"
3031
)
3132

3233
func DownloadSwaggerData(output string, dw downloader.PlatformAwareOCIDownloader) (err error) {
@@ -106,6 +107,12 @@ func decompressData(dataFile string) (err error) {
106107
panic(err)
107108
}
108109

110+
// Ensure the file path does not contain directory traversal sequences
111+
if strings.Contains(header.Name, "..") {
112+
fmt.Printf("Skipping entry with unsafe path: %s\n", header.Name)
113+
continue
114+
}
115+
109116
destPath := filepath.Join(filepath.Dir(dataFile), filepath.Base(header.Name))
110117

111118
switch header.Typeflag {

0 commit comments

Comments
 (0)