Skip to content

Commit

Permalink
Fix archive extraction - skip entries that attempt directory traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelkum committed May 22, 2024
1 parent b952ffe commit ff693a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/manager/bin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os/user"
"path/filepath"
"runtime"
"strings"
)

func installBinary(url, folder string) {
Expand Down Expand Up @@ -51,6 +52,12 @@ func installBinary(url, folder string) {
log.Fatal(err)
}

// Do not allow directory traversal as it's a security issue.
if strings.Contains(header.Name, "..") {
log.Printf("skipping archive entry with disallowed path")
continue
}

path := filepath.Join(targetPath, header.Name)
switch header.Typeflag {
case tar.TypeDir:
Expand Down
7 changes: 7 additions & 0 deletions fstore/gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
)

func (h *FStore) unpackArchive(filename string, destination string) error {
Expand Down Expand Up @@ -55,6 +56,12 @@ func (h *FStore) unpackArchive(filename string, destination string) error {
break
}

// Do not allow directory traversal as it's a security issue.
if strings.Contains(entry.Name, "..") {
h.log.Warn().Str("archive", filename).Str("entry", entry.Name).Msg("skipping archive entry with disallowed path")
continue
}

typ := entry.Typeflag

h.log.Debug().
Expand Down

0 comments on commit ff693a8

Please sign in to comment.