Skip to content

Commit 3d61bab

Browse files
loresusopoiana
authored andcommitted
fix: ensure extracted files are put inside dest dir
Signed-off-by: Lorenzo Susini <[email protected]>
1 parent cc92d41 commit 3d61bab

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

internal/utils/extract.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"os"
2424
"path/filepath"
25+
"strings"
2526
)
2627

2728
// ExtractTarGz extracts a *.tar.gz compressed archive and moves its content to destDir.
@@ -51,6 +52,10 @@ func ExtractTarGz(gzipStream io.Reader, destDir string) ([]string, error) {
5152
case tar.TypeDir:
5253
return nil, fmt.Errorf("unexepected dir inside the archive, expected to find only files without any tree structure")
5354
case tar.TypeReg:
55+
if strings.Contains(header.Name, "..") {
56+
return nil, fmt.Errorf("not allowed relative path in tar archive")
57+
}
58+
5459
f := filepath.Join(destDir, filepath.Clean(header.Name))
5560
outFile, err := os.Create(filepath.Clean(f))
5661
if err != nil {

0 commit comments

Comments
 (0)