From d8be06db4fa65dbf813b4012de84724ff60a535a Mon Sep 17 00:00:00 2001 From: Daniel Traynor <198297846+dantraynor@users.noreply.github.com> Date: Thu, 22 Oct 2026 06:13:00 +0000 Subject: [PATCH] fix(install): keep gh probes from aborting Windows PowerShell 5.1 Windows PowerShell 5.1 turns redirected native stderr into a terminating NativeCommandError under ErrorActionPreference=Stop, so an installed but signed-out gh aborted the installer before its exit-code check. Run the gh probes through a helper that scopes Continue to the call. Unsigned-release failures now point at the pinned release notes and say how to opt in, and the popup explains -AllowUnsigned next to its PowerShell commands without adding it to them. Fixes #151 --- .../src/popup/views/install-helpers.test.ts | 5 ++ .../shared/src/popup/views/install-helpers.ts | 22 ++++- scripts/install.ps1 | 26 ++++-- scripts/install.test.ps1 | 85 +++++++++++++++++++ 4 files changed, 128 insertions(+), 10 deletions(-) diff --git a/packages/shared/src/popup/views/install-helpers.test.ts b/packages/shared/src/popup/views/install-helpers.test.ts index 2e54457..70ac6a4 100644 --- a/packages/shared/src/popup/views/install-helpers.test.ts +++ b/packages/shared/src/popup/views/install-helpers.test.ts @@ -173,6 +173,9 @@ describe("renderInstallFlow", () => { const primary = root.querySelector(".helper-install-primary")!; expect(primary.textContent).toContain("without administrator access"); + const alternatives = root.querySelector("details")!; + expect(alternatives.querySelector("code")!.textContent).not.toContain("-AllowUnsigned"); + expect(alternatives.textContent).toContain("again with -AllowUnsigned added at the end"); expect(primary.querySelector("a")?.href).toBe( `${release}/download/${version}/tailchrome-helper-windows-x64.msi`, ); @@ -188,6 +191,8 @@ describe("renderInstallFlow", () => { expect(command).toContain(`${release}/download/${version}/tailchrome-install.ps1`); expect(command).toContain(`-Version '${version}'`); expect(primary.textContent).toContain("native ARM64"); + expect(command).not.toContain("-AllowUnsigned"); + expect(primary.textContent).toContain("again with -AllowUnsigned added at the end"); const alternatives = root.querySelector("details")!; expect(alternatives.open).toBe(false); expect(alternatives.textContent).toContain("x64 package (runs under emulation)"); diff --git a/packages/shared/src/popup/views/install-helpers.ts b/packages/shared/src/popup/views/install-helpers.ts index b064f30..fb96ead 100644 --- a/packages/shared/src/popup/views/install-helpers.ts +++ b/packages/shared/src/popup/views/install-helpers.ts @@ -320,6 +320,9 @@ function createPrimaryInstall( platform === "linux" ? unixInstallCommand() : powershellInstallCommand(); if (command) { card.appendChild(createCodeBlock(command)); + if (platform === "windows") { + card.appendChild(createUnsignedPowerShellHint()); + } } else { card.appendChild(createReleaseLink()); } @@ -431,7 +434,11 @@ function createAlternativeInstallDetails( if (platform === "windows" && architecture === "amd64") { appendAlternativeHeading(details, "PowerShell option"); - appendCommandIfAvailable(details, powershellInstallCommand()); + const command = powershellInstallCommand(); + appendCommandIfAvailable(details, command); + if (command) { + details.appendChild(createUnsignedPowerShellHint()); + } appendAdvancedDocs(details); return details; } @@ -482,6 +489,19 @@ function appendCommandIfAvailable( } } +/** + * The PowerShell installer requires an Authenticode signature unless the user + * explicitly opts in. Explain that opt-in here instead of baking it into the + * command, so signed releases keep rejecting an unsigned substitute (#151). + */ +function createUnsignedPowerShellHint(): HTMLElement { + const hint = document.createElement("p"); + hint.className = "install-step-hint"; + hint.textContent = + "If PowerShell stops at “Release is unsigned”, check the release notes. If they say this release's Windows helper is unsigned, run the command again with -AllowUnsigned added at the end."; + return hint; +} + function appendAdvancedDocs(container: HTMLElement): void { const docs = document.createElement("a"); docs.className = "install-advanced-docs"; diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 1ce2bd4..a2a8a4e 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -164,29 +164,36 @@ function Invoke-Download([string]$Uri, [string]$Path) { Invoke-WebRequest -UseBasicParsing -Uri $Uri -OutFile $Path } +function Invoke-NativeProbe([string]$Command, [string[]]$Arguments) { + # Windows PowerShell 5.1 turns redirected native stderr into a terminating + # NativeCommandError when ErrorActionPreference is Stop, so a probe that + # merely reports failure on stderr would abort the installer (#151). Probes + # report through their exit code; scope Continue to this call only. + $ErrorActionPreference = 'Continue' + & $Command @Arguments *> $null + return $LASTEXITCODE +} + function Test-AvailableAttestation([string]$ArtifactPath) { $gh = Get-Command gh -ErrorAction SilentlyContinue if (-not $gh) { Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.' return } - & $gh.Source attestation verify --help *> $null - if ($LASTEXITCODE -ne 0) { + if ((Invoke-NativeProbe $gh.Source @('attestation', 'verify', '--help')) -ne 0) { Write-Warning 'GitHub CLI attestation verification is unavailable; the checksum and artifact share the GitHub Release trust boundary.' return } - & $gh.Source auth status --hostname github.com *> $null - if ($LASTEXITCODE -ne 0) { + if ((Invoke-NativeProbe $gh.Source @('auth', 'status', '--hostname', 'github.com')) -ne 0) { Write-Warning 'GitHub CLI is not authenticated; the checksum and artifact share the GitHub Release trust boundary.' return } - & $gh.Source attestation verify $ArtifactPath --hostname github.com --repo $Repository *> $null - if ($LASTEXITCODE -ne 0) { + if ((Invoke-NativeProbe $gh.Source @('attestation', 'verify', $ArtifactPath, '--hostname', 'github.com', '--repo', $Repository)) -ne 0) { Fail 'GitHub artifact attestation verification failed.' } } -function Test-Authenticode([string]$ArtifactPath) { +function Test-Authenticode([string]$ArtifactPath, [string]$Version) { $signatureCommand = Get-Command Get-AuthenticodeSignature -ErrorAction SilentlyContinue if (-not $signatureCommand) { if ($AllowUnsigned -or $env:TAILCHROME_ALLOW_UNSIGNED_RELEASE -eq '1') { @@ -204,7 +211,8 @@ function Test-Authenticode([string]$ArtifactPath) { return } if ($signature.Status -eq 'NotSigned') { - Fail 'Release is unsigned; use -AllowUnsigned only for an explicitly approved unsigned release.' + $notes = if ($Version) { " Review the release notes at https://github.com/$Repository/releases/tag/$Version; if they approve this unsigned release, run the same command again with -AllowUnsigned added at the end." } else { '' } + Fail ('Release is unsigned; use -AllowUnsigned only for an explicitly approved unsigned release.' + $notes) } Fail "Windows signature verification failed: $($signature.Status)." } @@ -347,7 +355,7 @@ $releaseBase = "$ReleaseBaseDefault/$Version" Fail 'SHA-256 checksum verification failed.' } Test-AvailableAttestation $artifactPath - Test-Authenticode $artifactPath + Test-Authenticode $artifactPath $Version $stagePath = Join-Path $targetDirectory ('.tailchrome-stage-' + [guid]::NewGuid().ToString('N') + '.tmp') Copy-VerifiedStage $artifactPath $stagePath diff --git a/scripts/install.test.ps1 b/scripts/install.test.ps1 index 51b2e55..eb13798 100644 --- a/scripts/install.test.ps1 +++ b/scripts/install.test.ps1 @@ -6,6 +6,7 @@ $Installer = Join-Path $Root 'scripts/install.ps1' . $Installer $ProductionInvokeInstalledHelper = (Get-Command Invoke-InstalledHelper -CommandType Function).ScriptBlock $ProductionGetNativeArchitecture = (Get-Command Get-NativeArchitecture -CommandType Function).ScriptBlock +$ProductionTestAvailableAttestation = (Get-Command Test-AvailableAttestation -CommandType Function).ScriptBlock $TestsRun = 0 $TestsFailed = 0 @@ -146,6 +147,89 @@ if ($helperSuccess -eq 0 -and $helperFailure -eq 7) { FailTest 'keeps helper stdout out of Invoke-InstalledHelper exit-code results' ("success=[$helperSuccess] failure=[$helperFailure]") } +# A real native gh that reports failure on stderr. Under stock Windows +# PowerShell 5.1 with ErrorActionPreference=Stop, redirected stderr used to +# abort the installer before the exit-code check (#151). +$fakeGhDir = Join-Path ([IO.Path]::GetTempPath()) ('tailchrome-fake-gh-' + [guid]::NewGuid().ToString('N')) +New-Item -ItemType Directory -Path $fakeGhDir | Out-Null +if ($WindowsTest) { +@' +@echo off +if "%1"=="auth" ( + if "%TAILCHROME_FAKE_GH_MODE%"=="unauthenticated" ( + echo You are not logged into any GitHub hosts. 1>&2 + exit /b 1 + ) + exit /b 0 +) +if "%3"=="--help" exit /b 0 +if "%TAILCHROME_FAKE_GH_MODE%"=="verify-fails" ( + echo attestation verification failed 1>&2 + exit /b 1 +) +exit /b 0 +'@ | Set-Content -LiteralPath (Join-Path $fakeGhDir 'gh.cmd') +} else { +@' +#!/bin/sh +if [ "$1" = "auth" ]; then + if [ "$TAILCHROME_FAKE_GH_MODE" = "unauthenticated" ]; then + echo "You are not logged into any GitHub hosts." >&2 + exit 1 + fi + exit 0 +fi +if [ "$3" = "--help" ]; then exit 0; fi +if [ "$TAILCHROME_FAKE_GH_MODE" = "verify-fails" ]; then + echo "attestation verification failed" >&2 + exit 1 +fi +exit 0 +'@ | Set-Content -LiteralPath (Join-Path $fakeGhDir 'gh') + & chmod +x (Join-Path $fakeGhDir 'gh') +} +$savedPath = $env:PATH +$env:PATH = $fakeGhDir + [IO.Path]::PathSeparator + $env:PATH +try { + $env:TAILCHROME_FAKE_GH_MODE = 'unauthenticated' + try { + $probeOutput = (& $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-String) + if ($probeOutput -like '*GitHub CLI is not authenticated*') { + Pass 'warns instead of aborting when gh is installed but not authenticated' + } else { + FailTest 'warns instead of aborting when gh is installed but not authenticated' ("output=[$probeOutput]") + } + } catch { + FailTest 'warns instead of aborting when gh is installed but not authenticated' $_.Exception.Message + } + + $env:TAILCHROME_FAKE_GH_MODE = 'verify-fails' + Expect-Failure 'fails closed when gh attestation verification fails' 'GitHub artifact attestation verification failed' { + try { + & $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-Null + return '' + } catch { + return $_.Exception.Message + } + } + + $env:TAILCHROME_FAKE_GH_MODE = 'verified' + try { + $probeOutput = (& $ProductionTestAvailableAttestation (Join-Path $fakeGhDir 'artifact') 3>&1 | Out-String) + if (-not $probeOutput.Trim()) { + Pass 'accepts a verified gh attestation silently' + } else { + FailTest 'accepts a verified gh attestation silently' ("output=[$probeOutput]") + } + } catch { + FailTest 'accepts a verified gh attestation silently' $_.Exception.Message + } +} finally { + $env:PATH = $savedPath + Remove-Item Env:\TAILCHROME_FAKE_GH_MODE -ErrorAction SilentlyContinue + Remove-Item -LiteralPath $fakeGhDir -Recurse -Force -ErrorAction SilentlyContinue +} + New-Fixture $popupBin = Join-Path $script:Fixture "scriptblock bin/owner's helper" New-Item -ItemType Directory -Path $popupBin -Force | Out-Null @@ -249,6 +333,7 @@ $script:SignatureStatus = 'Invalid' Expect-Failure 'rejects invalid signature with unsigned opt-in' 'signature verification failed' { Invoke-Main -AllowUnsigned } New-Fixture Expect-Failure 'rejects unsigned release without opt-in' 'use -AllowUnsigned' { Invoke-Main } +Expect-Failure 'points unsigned-release failures at the pinned release notes' 'releases/tag/v1.2.3; if they approve this unsigned release, run the same command again with -AllowUnsigned' { Invoke-Main } New-Fixture $message = Invoke-Main -AllowUnsigned $destination = Join-Path $env:LOCALAPPDATA 'Tailchrome/tailchrome.exe'