Skip to content

Commit

Permalink
internal/releasesjson: Prevent path traversal (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Jan 18, 2023
1 parent b979d40 commit baca000
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/releasesjson/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os"
"path/filepath"
"runtime"
"strings"

"github.com/hashicorp/hc-install/internal/httpclient"
)
Expand Down Expand Up @@ -145,6 +146,11 @@ func (d *Downloader) DownloadAndUnpack(ctx context.Context, pv *ProductVersion,
defer r.Close()

for _, f := range r.File {
if strings.Contains(f.Name, "..") {
// While we generally trust the source ZIP file
// we still reject path traversal attempts as a precaution.
continue
}
srcFile, err := f.Open()
if err != nil {
return pkgFilePath, err
Expand Down

0 comments on commit baca000

Please sign in to comment.