Skip to content

Commit 9c5bcdf

Browse files
authored
fix(P0 Windows startup): smart signed WebView2 prerequisite (#845)
* feat(installer): signed Microsoft WebView2 prerequisite preflight and guarded bootstrapper * feat(P0 installer): run WebView2 smart prerequisite before VB-CABLE and GUI Ship the signed Microsoft Evergreen bootstrap helper in the Windows installer, execute only for interactive installs when WebView2 is missing, record diagnostics, preserve static MSVC CRT, VB-CABLE and existing audio configuration. Add deterministic Node and native Windows PowerShell policy contracts.
1 parent 6c373b9 commit 9c5bcdf

5 files changed

Lines changed: 183 additions & 3 deletions

File tree

‎installer/ArSonMix.iss‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ Type: files; Name: "{app}\README.md"
6363
Source: "{#SourceRoot}\VBCABLE_Driver_Pack45.zip"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion
6464
Source: "{#SourceRoot}\VB-CABLE-NOTICE.txt"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion
6565
Source: "ArSonMixVBCableInstall.ps1"; DestDir: "{app}\ThirdParty\VB-Audio"; Flags: ignoreversion
66+
; Microsoft-signed WebView2 Evergreen prerequisite, no bundled old runtime.
67+
Source: "ArSonMixWebView2Prerequisite.ps1"; DestDir: "{app}"; Flags: ignoreversion
6668
; The shutdown helper is EMBEDDED TEMPORARILY in Setup, never installed.
6769
; It handles installed legacy builds that do not implement the new event.
6870
Source: "ArSonMixUpdateShutdown.ps1"; Flags: dontcopy
@@ -94,6 +96,9 @@ Name: "{autoprograms}\Start ArSonMix with Recovery Profile"; Filename: "{app}\Ar
9496
; one new executable only after a successful interactive install/update.
9597
; Silent enterprise/FAT installs deliberately do not launch desktop audio.
9698
[Run]
99+
; WebView2 is a real GUI prerequisite. Check/install only when missing;
100+
; silent/enterprise/auto-update installs never fetch or alter OS components.
101+
Filename: "{sys}\WindowsPowerShell\v1.0\powershell.exe"; Parameters: "-NoLogo -NoProfile -ExecutionPolicy Bypass -File ""{app}\ArSonMixWebView2Prerequisite.ps1"""; WorkingDir: "{app}"; StatusMsg: "Checking Microsoft WebView2 for ArSonMix..."; Flags: runasoriginaluser skipifsilent waituntilterminated runhidden
97102
; Interactive Setup automatically checks installed and pending VB-CABLE devices.
98103
; Only a missing driver can reach the verified vendor installer and Windows UAC.
99104
; The next entry opens ArSonMix even if the driver needs a restart or is declined.

‎installer/ArSonMixStartupDiagnostics.ps1‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ if ($registrations) {
3636
} else {
3737
$lines += 'WebView2 Evergreen registration absent. Download or repair the Microsoft WebView2 Runtime.'
3838
}
39+
$preflight = Join-Path $folder 'webview2-prerequisite.json'
40+
if (Test-Path -LiteralPath $preflight -PathType Leaf) {
41+
try {
42+
$prereqStatus = Get-Content -LiteralPath $preflight -Raw | ConvertFrom-Json -ErrorAction Stop
43+
$lines += "Installer WebView2 prerequisite: $($prereqStatus.state)"
44+
if ($prereqStatus.state -eq 'NEEDS_ATTENTION') {
45+
$lines += "Installer dependency detail: $($prereqStatus.detail)"
46+
}
47+
} catch {
48+
$lines += 'Installer WebView2 prerequisite status unreadable.'
49+
}
50+
}
3951
$startupLog = Join-Path $folder 'startup-failure.txt'
4052
if (Test-Path -LiteralPath $startupLog -PathType Leaf) {
4153
$lines += ''
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# SPDX-License-Identifier: AGPL-3.0-only
2+
# Interactive installer dependency preflight, never a realtime audio callback.
3+
[CmdletBinding()]param([switch]$PolicySelfTest)
4+
Set-StrictMode -Version Latest
5+
$ErrorActionPreference='Stop'
6+
$official='https://go.microsoft.com/fwlink/p/?LinkId=2124703'
7+
$guid='{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}'
8+
function Valid-Version([string]$value) {
9+
if($value -notmatch '^\d+\.\d+\.\d+\.\d+$'){return $false}
10+
try {return ([version]$value) -ge [version]'109.0.0.0'}catch{return $false}
11+
}
12+
function Microsoft-Uri([uri]$uri) {
13+
if($null -eq $uri -or $uri.Scheme -cne 'https'){return $false}
14+
$hostName=$uri.DnsSafeHost.ToLowerInvariant()
15+
return $hostName -eq 'microsoft.com' -or $hostName.EndsWith('.microsoft.com')
16+
}
17+
function Microsoft-Signer($signature) {
18+
if($null -eq $signature -or [string]$signature.Status -cne 'Valid' -or
19+
$null -eq $signature.SignerCertificate){return $false}
20+
return [string]$signature.SignerCertificate.Subject -match '(?i)(^|,\s*)(CN|O)=Microsoft Corporation(,|$)'
21+
}
22+
if($PolicySelfTest) {
23+
$good=[pscustomobject]@{Status='Valid';SignerCertificate=[pscustomobject]@{Subject='CN=Microsoft Corporation, O=Microsoft Corporation'}}
24+
$bad=[pscustomobject]@{Status='NotTrusted';SignerCertificate=[pscustomobject]@{Subject='CN=Microsoft Corporation'}}
25+
if(-not (Valid-Version '120.0.0.1') -or (Valid-Version '0.0.0.0') -or
26+
(Valid-Version 'bogus') -or (Valid-Version '108.0.0.1') -or
27+
-not (Microsoft-Uri ([uri]$official)) -or
28+
(Microsoft-Uri ([uri]'http://go.microsoft.com/setup.exe')) -or
29+
(Microsoft-Uri ([uri]'https://malicious-microsoft.com/setup.exe')) -or
30+
-not (Microsoft-Signer $good) -or (Microsoft-Signer $bad)){
31+
throw 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_FAIL'
32+
}
33+
Write-Output 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS'
34+
exit 0
35+
}
36+
$folder=Join-Path $env:LOCALAPPDATA 'ArSonMix\diagnostics'
37+
$report=Join-Path $folder 'webview2-prerequisite.json'
38+
function Record([string]$state,[string]$detail) {
39+
try {
40+
[IO.Directory]::CreateDirectory($folder)|Out-Null
41+
$temp=$report+'.'+[guid]::NewGuid().ToString('N')+'.tmp'
42+
[ordered]@{schema='arsonmix.webview2-prerequisite.v1';state=$state;detail=$detail;utc=[DateTime]::UtcNow.ToString('o')} |
43+
ConvertTo-Json -Compress | Set-Content -LiteralPath $temp -Encoding UTF8
44+
Move-Item -LiteralPath $temp -Destination $report -Force
45+
}catch{Write-Warning ('Unable to save WebView2 diagnostic: '+$_.Exception.Message)}
46+
}
47+
function Find-EvergreenRuntime {
48+
$keys=@(
49+
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\$guid",
50+
"HKLM:\SOFTWARE\Microsoft\EdgeUpdate\Clients\$guid",
51+
"HKCU:\SOFTWARE\Microsoft\EdgeUpdate\Clients\$guid",
52+
"HKCU:\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\$guid"
53+
)
54+
$roots=@(
55+
(Join-Path $env:LOCALAPPDATA 'Microsoft\EdgeWebView\Application'),
56+
(Join-Path ([Environment]::GetFolderPath('ProgramFilesX86')) 'Microsoft\EdgeWebView\Application'),
57+
(Join-Path $env:ProgramFiles 'Microsoft\EdgeWebView\Application')
58+
) | Select-Object -Unique
59+
foreach($key in $keys){
60+
try {
61+
$pv=[string](Get-ItemProperty -LiteralPath $key -Name pv -ErrorAction Stop).pv
62+
if(-not (Valid-Version $pv)){continue}
63+
foreach($root in $roots){
64+
if(Test-Path -LiteralPath (Join-Path (Join-Path $root $pv) 'msedgewebview2.exe') -PathType Leaf){return $pv}
65+
}
66+
}catch{Write-Verbose ('WebView2 registration query: '+$_.Exception.Message)}
67+
}
68+
return ''
69+
}
70+
$work=$null
71+
try {
72+
$os=Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop
73+
if(-not [Environment]::Is64BitOperatingSystem -or [int]$os.CurrentBuildNumber -lt 17763){
74+
Record 'UNSUPPORTED_OS' 'ArSonMix requires Windows 10 build 17763+ x64 or Windows 11 x64'
75+
exit 3
76+
}
77+
$installed=Find-EvergreenRuntime
78+
if($installed){
79+
Record 'ALREADY_PRESENT' ('WebView2 '+$installed+' is installed; no changes needed')
80+
Write-Output 'ARSONMIX_WEBVIEW2_ALREADY_PRESENT'
81+
exit 0
82+
}
83+
# Download only when missing. Final HTTPS host and Microsoft Authenticode
84+
# must both validate. No package from third-party mirrors is ever executed.
85+
$work=Join-Path $env:TEMP ('arsonmix-webview2-'+[guid]::NewGuid().ToString('N'))
86+
[IO.Directory]::CreateDirectory($work)|Out-Null
87+
$file=Join-Path $work 'MicrosoftEdgeWebView2Setup.exe'
88+
[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12
89+
$request=[Net.HttpWebRequest]::Create($official)
90+
$request.AllowAutoRedirect=$true
91+
$request.MaximumAutomaticRedirections=8
92+
$request.Timeout=20000
93+
$request.ReadWriteTimeout=20000
94+
$response=$request.GetResponse()
95+
try {
96+
if(-not (Microsoft-Uri $response.ResponseUri)){throw 'Unapproved Microsoft bootstrapper redirect host'}
97+
$stream=$response.GetResponseStream()
98+
$output=[IO.File]::Open($file,[IO.FileMode]::CreateNew,[IO.FileAccess]::Write)
99+
try {
100+
$bytes=New-Object byte[] 65536
101+
$total=0
102+
while(($n=$stream.Read($bytes,0,$bytes.Length)) -gt 0){
103+
$total+=$n
104+
if($total -gt 16777216){throw 'Oversized WebView2 bootstrapper'}
105+
$output.Write($bytes,0,$n)
106+
}
107+
if($total -lt 32768){throw 'Incomplete WebView2 download'}
108+
}finally{$output.Dispose();$stream.Dispose()}
109+
}finally{$response.Dispose()}
110+
$signature=Get-AuthenticodeSignature -LiteralPath $file -ErrorAction Stop
111+
if(-not (Microsoft-Signer $signature)){throw 'Untrusted WebView2 bootstrapper (not executed)'}
112+
# Official supported Evergreen installer switches; respects Windows policy.
113+
$process=Start-Process -FilePath $file -ArgumentList @('/silent','/install') -Wait -PassThru -ErrorAction Stop
114+
if($process.ExitCode -ne 0){throw ('Microsoft WebView2 setup failed: '+$process.ExitCode)}
115+
$installed=''
116+
for($i=0;$i -lt 5;$i++){
117+
$installed=Find-EvergreenRuntime
118+
if($installed){break}
119+
Start-Sleep -Seconds 2
120+
}
121+
if(-not $installed){throw 'WebView2 setup finished but runtime was not detected'}
122+
Record 'INSTALLED' ('WebView2 '+$installed+' verified')
123+
Write-Output 'ARSONMIX_WEBVIEW2_INSTALLED'
124+
exit 0
125+
}catch{
126+
# Offline, group-policy, restricted permissions and failed downloads are
127+
# recoverable. Do not loop, claim success, or delete user session data.
128+
Record 'NEEDS_ATTENTION' $_.Exception.Message
129+
Write-Warning ('WebView2 installation incomplete: '+$_.Exception.Message)
130+
exit 2
131+
}finally{
132+
if($work -and (Test-Path -LiteralPath $work)){
133+
Remove-Item -LiteralPath $work -Recurse -Force -ErrorAction SilentlyContinue
134+
}
135+
}

‎scripts/test_inno_graceful_update_windows.ps1‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ if($LASTEXITCODE -ne 0 -or $policyOutput -notcontains 'ARSONMIX_UPDATER_POLICY_P
1616
}
1717
Write-Host "ARSONMIX_UPDATER_POLICY_PASS"
1818

19+
# Check the exact shipped WebView2 helper in a pure non-network policy mode.
20+
$webviewPolicy=Join-Path (Resolve-Path .).Path "installer/ArSonMixWebView2Prerequisite.ps1"
21+
$webviewOutput=& "$env:WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -File $webviewPolicy -PolicySelfTest
22+
if($LASTEXITCODE -ne 0 -or $webviewOutput -notcontains 'ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS') {
23+
throw "WebView2 secure bootstrapper policy failed: $webviewOutput"
24+
}
25+
Write-Host "ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS"
26+
1927
$ErrorActionPreference="Stop"
2028
$root=(Resolve-Path .).Path
2129
$work=Join-Path $env:RUNNER_TEMP ("arsonmix-inno-smoke-"+[guid]::NewGuid().ToString("N"))

‎tests/windows_installer_contract_test.mjs‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ test('interactive Setup automatically checks for signed VB-CABLE while mixer lau
4747
assert.match(iss, /VBCABLE_Driver_Pack45\.zip/);
4848
const run = iss.slice(iss.indexOf('[Run]'), iss.indexOf('[Code]'));
4949
const entries = run.split('\n').filter(line => line.startsWith('Filename:'));
50-
assert.equal(entries.length, 2);
51-
assert.match(entries[0], /ArSonMixVBCableInstall\.ps1/);
50+
assert.equal(entries.length, 3);
51+
assert.match(entries[0], /ArSonMixWebView2Prerequisite\.ps1/);
5252
assert.match(entries[0], /Flags: runasoriginaluser skipifsilent waituntilterminated runhidden/);
53-
assert.match(entries[1], /^Filename: "\{app\}\\ArSonMix\.exe"/);
53+
assert.match(entries[1], /ArSonMixVBCableInstall\.ps1/);
54+
assert.match(entries[1], /Flags: runasoriginaluser skipifsilent waituntilterminated runhidden/);
55+
assert.match(entries[2], /^Filename: "\{app\}\\ArSonMix\.exe"/);
5456
for (const entry of entries) assert.doesNotMatch(entry, /;\s*(Check|Tasks):/i);
5557
assert.match(iss, /^RestartIfNeededByRun=no$/m);
5658
assert.doesNotMatch(iss + bootstrap, /VBCableRestart|RestartMarker|CanLaunchMixer|function NeedRestart/);
@@ -104,6 +106,24 @@ test('interactive Setup automatically checks for signed VB-CABLE while mixer lau
104106
assert.match(iss, /Flags: runasoriginaluser skipifsilent waituntilterminated/);
105107
});
106108

109+
test('WebView2 GUI prerequisite runs only on interactive setup from Microsoft-signed bootstrapper', () => {
110+
const helper=read('installer/ArSonMixWebView2Prerequisite.ps1');
111+
assert.match(iss, /Source: "ArSonMixWebView2Prerequisite\.ps1"; DestDir: "\{app\}"/);
112+
assert.match(helper, /ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS/);
113+
assert.match(helper, /go\.microsoft\.com\/fwlink\/p\/\?LinkId=2124703/);
114+
assert.match(helper, /Get-AuthenticodeSignature/);
115+
assert.match(helper, /Microsoft-Signer/);
116+
assert.match(helper, /Microsoft-Uri \$response\.ResponseUri/);
117+
assert.match(helper, /-ArgumentList @\('\/silent','\/install'\)/);
118+
assert.match(helper, /ARSONMIX_WEBVIEW2_ALREADY_PRESENT/);
119+
assert.match(helper, /ARSONMIX_WEBVIEW2_INSTALLED/);
120+
assert.match(helper, /NEEDS_ATTENTION/);
121+
assert.ok(helper.indexOf('if($installed)') < helper.indexOf('$request.GetResponse()'));
122+
assert.ok(helper.indexOf('Get-AuthenticodeSignature') < helper.indexOf('Start-Process -FilePath $file'));
123+
assert.doesNotMatch(helper, /vcredist|vc_redist|TrustedPublisher|SetDefaultEndpoint|--safe-webview-profile/i);
124+
assert.match(read('scripts/test_inno_graceful_update_windows.ps1'), /ARSONMIX_WEBVIEW2_PREREQUISITE_POLICY_PASS/);
125+
});
126+
107127
test('single installer preflight requests graceful shutdown; Restart Manager cannot force old mixer', () => {
108128
assert.match(iss, /^CloseApplications=no$/m);
109129
assert.doesNotMatch(iss, /^CloseApplicationsFilter=/m);

0 commit comments

Comments
 (0)