Skip to content

Commit 0c07e98

Browse files
authored
Harden foundryup temp handling: secure mktemp and quote tar paths (#11771)
Update foundryup
1 parent 0867fc1 commit 0c07e98

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

foundryup/foundryup

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ main() {
165165
say "checking if forge, cast, anvil, and chisel for $FOUNDRYUP_TAG version are already installed"
166166

167167
# Create a temporary directory to store the attestation link and artifact.
168-
tmp_dir="$(mktemp -d 2>/dev/null || echo ".")"
168+
tmp_dir="$(mktemp -d 2>/dev/null)" || err "failed to create temp dir"
169169
tmp="$tmp_dir/attestation.txt"
170170
ensure download "$ATTESTATION_URL" "$tmp"
171171

@@ -255,17 +255,19 @@ main() {
255255
# Download and extract the binaries archive
256256
say "downloading forge, cast, anvil, and chisel for $FOUNDRYUP_TAG version"
257257
if [ "$PLATFORM" = "win32" ]; then
258-
tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.zip"
258+
tmp="$(mktemp -d 2>/dev/null)" || err "failed to create temp dir"
259+
tmp="$tmp/foundry.zip"
259260
ensure download "$BIN_ARCHIVE_URL" "$tmp"
260261
ensure unzip "$tmp" -d "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG"
261262
rm -f "$tmp"
262263
else
263-
tmp="$(mktemp -d 2>/dev/null || echo ".")/foundry.tar.gz"
264+
tmp="$(mktemp -d 2>/dev/null)" || err "failed to create temp dir"
265+
tmp="$tmp/foundry.tar.gz"
264266
ensure download "$BIN_ARCHIVE_URL" "$tmp"
265267
# Make sure it's a valid tar archive.
266-
ensure tar tf $tmp 1> /dev/null
268+
ensure tar tf "$tmp" 1> /dev/null
267269
ensure mkdir -p "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG"
268-
ensure tar -C "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" -xvf $tmp
270+
ensure tar -C "$FOUNDRY_VERSIONS_DIR/$FOUNDRYUP_TAG" -xvf "$tmp"
269271
rm -f "$tmp"
270272
fi
271273

0 commit comments

Comments
 (0)