Skip to content

Commit 5fcdb89

Browse files
sec(install): validate redirect URL origin before trusting resolved version
resolve_redirect() follows HTTP redirects to determine the latest release tag, but never validated that the final URL still pointed to the expected GitHub repository. A compromised CDN, DNS poisoning, or an open redirect could cause the installer to extract a version tag from — and subsequently download binaries from — an attacker-controlled origin. Add origin validation: reject resolved URLs that don't match https://github.com/NVIDIA/OpenShell/*. Also cap redirect depth in download() to 5 as defense-in-depth. Closes #638
1 parent a7ebf3a commit 5fcdb89

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

install.sh

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,27 +87,38 @@ check_downloader() {
8787
}
8888

8989
# Download a URL to a file. Outputs nothing on success.
90+
# Limits redirects to prevent open-redirect abuse from download URLs.
9091
download() {
9192
_url="$1"
9293
_output="$2"
9394

9495
if has_cmd curl; then
95-
curl -fLsS --retry 3 -o "$_output" "$_url"
96+
curl -fLsS --retry 3 --max-redirs 5 -o "$_output" "$_url"
9697
elif has_cmd wget; then
97-
wget -q --tries=3 -O "$_output" "$_url"
98+
wget -q --tries=3 --max-redirect=5 -O "$_output" "$_url"
9899
fi
99100
}
100101

101102
# Follow a URL and print the final resolved URL (for detecting redirect targets).
103+
# Validates that the final URL is still within the expected GitHub origin to
104+
# prevent redirect-based attacks (e.g., compromised CDN or DNS poisoning).
102105
resolve_redirect() {
103106
_url="$1"
104107

105108
if has_cmd curl; then
106-
curl -fLsS -o /dev/null -w '%{url_effective}' "$_url"
109+
_resolved_url="$(curl -fLsS -o /dev/null -w '%{url_effective}' "$_url")"
107110
elif has_cmd wget; then
108111
# wget --spider follows redirects; capture the final Location from stderr
109-
wget --spider --max-redirect=10 "$_url" 2>&1 | sed -n 's/^.*Location: \([^ ]*\).*/\1/p' | tail -1
112+
_resolved_url="$(wget --spider --max-redirect=10 "$_url" 2>&1 | sed -n 's/^.*Location: \([^ ]*\).*/\1/p' | tail -1)"
110113
fi
114+
115+
# Verify the final URL points to the expected GitHub repository.
116+
case "$_resolved_url" in
117+
https://github.com/${REPO}/*) ;;
118+
*) error "redirect resolved to unexpected origin: ${_resolved_url} (expected https://github.com/${REPO}/...)" ;;
119+
esac
120+
121+
echo "$_resolved_url"
111122
}
112123

113124
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)