Skip to content

Commit

Permalink
Use home dir as temp directory
Browse files Browse the repository at this point in the history
This prevents the temp directory from being created in /tmp/, which is world writable. This fixes a potential race condition where the downloaded CLI binary could be replaced by an attacker before execution.
  • Loading branch information
Piccirello committed Oct 10, 2020
1 parent cb196ed commit 337ebc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion pkg/utils/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func WriteFile(filename string, data []byte, perm os.FileMode) error {

// WriteTempFile writes data to a unique temp file and returns the file name
func WriteTempFile(name string, data []byte, perm os.FileMode) (string, error) {
tmpFile, err := ioutil.TempFile(os.TempDir(), fmt.Sprintf("%s.", name))
// create hidden file in user's home dir to ensure no other users have write access
tmpFile, err := ioutil.TempFile(HomeDir(), fmt.Sprintf(".%s.", name))
if err != nil {
return "", err
}
Expand Down
3 changes: 2 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ url="https://cli.doppler.com/download?os=$os&arch=$arch&format=$format"

# download binary
if [ -x "$(command -v curl)" ] || [ -x "$(command -v wget)" ]; then
tempdir="$(mktemp -d)"
# create hidden temp dir in user's home directory to ensure no other users have write perms
tempdir="$(mktemp -d ~/.tmp.XXXXXXXX)"
log_debug "Using temp directory $tempdir"

echo "Downloading latest release"
Expand Down

0 comments on commit 337ebc7

Please sign in to comment.