Skip to content

Commit 0d4208b

Browse files
authored
fix(pkgmgr): guard against zip name path traversal (#360)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent 4721c69 commit 0d4208b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

pkgmgr/registry.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Blink Labs Software
1+
// Copyright 2025 Blink Labs Software
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -172,12 +172,17 @@ func registryPackagesUrl(cfg Config, validate bool) ([]Package, error) {
172172
}
173173
// Ensure there are no parent dir references in path
174174
if strings.Contains(zipFile.Name, "..") {
175-
continue
175+
return nil, fmt.Errorf("parent path reference in zip name")
176176
}
177+
// #nosec G305
177178
outPath := filepath.Join(
178179
cachePath,
179180
zipFile.Name,
180181
)
182+
// Ensure our path is sane to prevent the gosec issue above
183+
if !strings.HasPrefix(outPath, filepath.Clean(cachePath)) {
184+
return nil, fmt.Errorf("zip extraction path mismatch")
185+
}
181186
// Create parent dir(s)
182187
if err := os.MkdirAll(filepath.Dir(outPath), fs.ModePerm); err != nil {
183188
return nil, err

0 commit comments

Comments
 (0)