Skip to content

Bug: Double-quoted trap in tfenv-install allows path injection #455

@Zordrak

Description

@Zordrak

Description

In libexec/tfenv-install line 173, the cleanup trap uses double quotes with variable expansion:

trap "rm -rf ${download_tmp}" EXIT

Because the trap string is double-quoted, ${download_tmp} is expanded at trap definition time, not execution time. If the temp directory path contains spaces or shell metacharacters, the rm -rf command will be word-split.

For example, if mktemp returns a path like /tmp/tfenv download.XXXXXX.abc, the trap would execute rm -rf /tmp/tfenv download.XXXXXX.abc — attempting to delete /tmp/tfenv and download.XXXXXX.abc as separate arguments.

Expected

Use single quotes and proper quoting:

trap 'rm -rf ""' EXIT

Or better, capture to a variable and use a function:

cleanup() { rm -rf "${download_tmp}"; }
trap cleanup EXIT

Impact

With adversarial or unusual temp paths, the cleanup could delete unintended files. In practice, mktemp on most systems does not produce paths with spaces, but this is still a correctness issue.

Found via

Code review of all source files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions