Skip to content

Commit e550d5d

Browse files
committed
fix(security): add path traversal validation to all installer scripts
- Validate tool name argument rejects "/" and ".." in install_tool.sh (entry point) and all 10 installer scripts (defense in depth) - Extract print_installed_status() helper in guide.sh to reduce duplicated installed/not-installed display logic
1 parent 9854e15 commit e550d5d

13 files changed

Lines changed: 86 additions & 10 deletions

scripts/guide.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ osc8() {
165165
[ -n "$url" ] && printf '\e]8;;%s\e\\%s\e]8;;\e\\' "$url" "$text" || printf '%s' "$text"
166166
}
167167

168+
# Print installed status line (reusable for auto-update and interactive prompts)
169+
print_installed_status() {
170+
local installed="$1"
171+
local method="$2"
172+
if [ -z "$installed" ]; then
173+
printf " installed: not installed\n"
174+
else
175+
printf " installed: %s via %s\n" "$installed" "${method:-unknown}"
176+
fi
177+
}
178+
168179
# Check for multiple installations and print warning if found
169180
# Args: catalog_tool_name
170181
# Returns: 0 always (informational only)
@@ -291,11 +302,7 @@ process_tool() {
291302
# BUT: multi-version tools always prompt (more significant operation)
292303
if [ "$auto_update" = "true" ] && [ -z "$is_multi_version" ]; then
293304
printf "\n==> %s %s [auto-update]\n" "$icon" "$display"
294-
if [ -z "$installed" ]; then
295-
printf " installed: not installed\n"
296-
else
297-
printf " installed: %s via %s\n" "$installed" "${method:-unknown}"
298-
fi
305+
print_installed_status "$installed" "$method"
299306
# Show target; for self-managed tools (skip_upstream) show "self-managed" instead of <unknown>
300307
local target_display="${latest:-<unknown>}"
301308
local skip_upstream="$(catalog_get_property "$catalog_tool" skip_upstream)"
@@ -349,11 +356,7 @@ process_tool() {
349356
printf "\n==> %s %s\n" "$icon" "$display"
350357
[ -n "$description" ] && printf " %s\n" "$description"
351358
[ -n "$homepage" ] && printf " Homepage: %s\n" "$(osc8 "$homepage" "$homepage")"
352-
if [ -z "$installed" ]; then
353-
printf " installed: not installed\n"
354-
else
355-
printf " installed: %s via %s\n" "$installed" "${method:-unknown}"
356-
fi
359+
print_installed_status "$installed" "$method"
357360

358361
check_multi_installs "$catalog_tool"
359362

scripts/install_tool.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ if [ -z "$TOOL" ]; then
1717
exit 1
1818
fi
1919

20+
# Validate tool name to prevent path traversal
21+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
22+
echo "[$TOOL] Error: Invalid tool name" >&2
23+
exit 1
24+
fi
25+
2026
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
2127

2228
# Check if tool has catalog entry

scripts/installers/dedicated_script.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ if [ -z "$TOOL" ]; then
1111
exit 1
1212
fi
1313

14+
# Validate tool name to prevent path traversal
15+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
16+
echo "Error: Invalid tool name: $TOOL" >&2
17+
exit 1
18+
fi
19+
1420
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
1521
if [ ! -f "$CATALOG_FILE" ]; then
1622
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

scripts/installers/docker_plugin.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ if [ -z "$TOOL" ]; then
1313
exit 1
1414
fi
1515

16+
# Validate tool name to prevent path traversal
17+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
18+
echo "Error: Invalid tool name: $TOOL" >&2
19+
exit 1
20+
fi
21+
1622
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
1723
if [ ! -f "$CATALOG_FILE" ]; then
1824
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

scripts/installers/gcloud_installer.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
77
. "$DIR/lib/install_strategy.sh"
88

99
TOOL="${1:-gcloud}"
10+
11+
# Validate tool name to prevent path traversal
12+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
13+
echo "Error: Invalid tool name: $TOOL" >&2
14+
exit 1
15+
fi
16+
1017
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
1118

1219
if [ ! -f "$CATALOG_FILE" ]; then

scripts/installers/github_clone.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ if [ -z "$TOOL" ]; then
1111
exit 1
1212
fi
1313

14+
# Validate tool name to prevent path traversal
15+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
16+
echo "Error: Invalid tool name: $TOOL" >&2
17+
exit 1
18+
fi
19+
1420
ACTION="${2:-install}"
1521

1622
CATALOG_FILE="$DIR/../catalog/$TOOL.json"

scripts/installers/github_release_binary.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ if [ -z "$TOOL" ]; then
2020
exit 1
2121
fi
2222

23+
# Validate tool name to prevent path traversal
24+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
25+
echo "Error: Invalid tool name: $TOOL" >&2
26+
exit 1
27+
fi
28+
2329
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
2430
if [ ! -f "$CATALOG_FILE" ]; then
2531
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

scripts/installers/go_install.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ if [ -z "$TOOL" ]; then
1212
exit 1
1313
fi
1414

15+
# Validate tool name to prevent path traversal
16+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
17+
echo "Error: Invalid tool name: $TOOL" >&2
18+
exit 1
19+
fi
20+
1521
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
1622
if [ ! -f "$CATALOG_FILE" ]; then
1723
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

scripts/installers/hashicorp_zip.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ if [ -z "$TOOL" ]; then
1212
exit 1
1313
fi
1414

15+
# Validate tool name to prevent path traversal
16+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
17+
echo "Error: Invalid tool name: $TOOL" >&2
18+
exit 1
19+
fi
20+
1521
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
1622
if [ ! -f "$CATALOG_FILE" ]; then
1723
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

scripts/installers/npm_global.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ if [ -z "$TOOL" ]; then
1818
exit 1
1919
fi
2020

21+
# Validate tool name to prevent path traversal
22+
if [[ "$TOOL" == *"/"* ]] || [[ "$TOOL" == *".."* ]]; then
23+
echo "Error: Invalid tool name: $TOOL" >&2
24+
exit 1
25+
fi
26+
2127
CATALOG_FILE="$DIR/../catalog/$TOOL.json"
2228
if [ ! -f "$CATALOG_FILE" ]; then
2329
echo "Error: Catalog file not found: $CATALOG_FILE" >&2

0 commit comments

Comments
 (0)