Skip to content

Commit 70a50b0

Browse files
committed
Fix Windows install security warning from Invoke-WebRequest
Replace the artifact probe loop (Invoke-WebRequest HEAD requests) with a membership check against the GitHub release asset list already fetched via Invoke-RestMethod. This eliminates Invoke-WebRequest entirely, which was triggering a PowerShell 5.1 IE-parser security warning on every install. - For 'latest': extract $ReleaseAssets from the existing API response at no extra cost. - For a specific version: add an Invoke-RestMethod call to /releases/tags/{tag} to fetch the same asset list. - Replace the HEAD probe loop with a simple -contains membership check. - Improve the error message: show available Windows assets from the release when no compatible binary is found. Fixes #118
1 parent 2d507a6 commit 70a50b0

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

install.ps1

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ if ($Version -eq "latest") {
109109
try {
110110
$Response = Invoke-RestMethod -Uri $ApiUrl -Headers @{ "Accept" = "application/vnd.github.v3+json" }
111111
$Tag = $Response.tag_name
112+
$ReleaseAssets = $Response.assets | ForEach-Object { $_.name }
112113
} catch {
113114
Write-Output "Install Failed:"
114115
Write-Output " Could not determine the latest release from the GitHub API."
@@ -118,6 +119,18 @@ if ($Version -eq "latest") {
118119
}
119120
} else {
120121
$Tag = $Version
122+
$ApiUrl = "https://api.github.com/repos/${Repo}/releases/tags/${Tag}"
123+
124+
try {
125+
$Response = Invoke-RestMethod -Uri $ApiUrl -Headers @{ "Accept" = "application/vnd.github.v3+json" }
126+
$ReleaseAssets = $Response.assets | ForEach-Object { $_.name }
127+
} catch {
128+
Write-Output "Install Failed:"
129+
Write-Output " Could not fetch release ${Tag} from the GitHub API."
130+
Write-Output " URL: $ApiUrl"
131+
Write-Output " $_"
132+
exit 1
133+
}
121134
}
122135

123136
# ── Resolve artifact name with automatic x64 fallback ────────────────────────
@@ -127,6 +140,10 @@ if ($Version -eq "latest") {
127140
# github-code-search-windows-x64-baseline.exe — compatible with any x86-64 CPU
128141
# github-code-search-windows-x64.exe — legacy alias kept for back-compat
129142
# github-code-search-windows-arm64.exe — ARM64
143+
#
144+
# Artifact availability is checked against the GitHub release asset list already
145+
# fetched above — no extra network request needed, and no Invoke-WebRequest
146+
# which triggers a security warning on Windows PowerShell 5.1.
130147

131148
$CandidateTargets = @($Target)
132149
if ($Target -eq "x64-modern") {
@@ -139,22 +156,21 @@ if ($Target -eq "x64-modern") {
139156
$Artifact = $null
140157
foreach ($Candidate in $CandidateTargets) {
141158
$CandidateArtifact = "${BinaryName}-windows-${Candidate}.exe"
142-
$CheckUrl = "https://github.com/${Repo}/releases/download/${Tag}/${CandidateArtifact}"
143-
try {
144-
# -UseBasicParsing is removed in PowerShell 6+ (pwsh); omit it for compat.
145-
$Null = Invoke-WebRequest -Uri $CheckUrl -Method Head -ErrorAction Stop
159+
if ($ReleaseAssets -contains $CandidateArtifact) {
146160
$Artifact = $CandidateArtifact
147161
$Target = $Candidate
148162
break
149-
} catch {
150-
Write-Output " Variant windows-${Candidate} not found in release ${Tag}, trying next..."
151163
}
152164
}
153165

154166
if ($null -eq $Artifact) {
167+
$AvailableWindows = $ReleaseAssets | Where-Object { $_ -like "*windows*" }
155168
Write-Output "Install Failed:"
156169
Write-Output " No compatible Windows binary found for ${Tag}."
157170
Write-Output " Tried: $($CandidateTargets -join ', ')"
171+
if ($AvailableWindows) {
172+
Write-Output " Available Windows assets: $($AvailableWindows -join ', ')"
173+
}
158174
exit 1
159175
}
160176

0 commit comments

Comments
 (0)