Skip to content

The agent that grows with you

fix(desktop): trust a remote HERMES_HOME only when it exists on the remote (#118988, salvage #119022)

teknium1a767190e84b4
diff --git a/apps/desktop/electron/windows-remote-lifecycle.test.ts b/apps/desktop/electron/windows-remote-lifecycle.test.ts
index ebc971cac17..b5695c1bc09 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.test.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.test.ts
@@ -196,6 +196,10 @@ test('Windows probe validates Hermes and Python topology before selection', asyn
const explicitCheck = script.indexOf('if($explicit){Assert-NoReparse $explicit $false;')
const explicitPythonCheck = script.indexOf('Assert-NoReparse $explicitPython $false')
+ const envHome = script.indexOf('$hermesHome=$env:HERMES_HOME')
+ // #118988: HERMES_HOME is trusted only when it is a directory on the remote; anything else
+ // (stale User-scope value, client path leaked over SSH) falls back to the remote default.
+ const envHomeGuard = script.indexOf('Test-Path -LiteralPath $hermesHome -PathType Container')
const fallbackJoin = script.indexOf('Join-Path $hermesHome')
const candidatePythonCheck = script.indexOf('Assert-NoReparse $candidatePython $true')
const candidateSelection = script.indexOf('Get-Item -LiteralPath $candidate')
@@ -205,7 +209,9 @@ test('Windows probe validates Hermes and Python topology before selection', asyn
assert.ok(explicitCheck >= 0)
assert.ok(explicitCheck < explicitPythonCheck)
- assert.ok(explicitPythonCheck < fallbackJoin)
+ assert.ok(explicitPythonCheck < envHome)
+ assert.ok(envHome < envHomeGuard)
+ assert.ok(envHomeGuard < fallbackJoin)
assert.ok(candidatePythonCheck >= 0)
assert.ok(candidatePythonCheck < candidateSelection)
assert.ok(pythonJoin >= 0)
diff --git a/apps/desktop/electron/windows-remote-lifecycle.ts b/apps/desktop/electron/windows-remote-lifecycle.ts
index d042a51bcd2..6a3d846c633 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.ts
@@ -35,8 +35,11 @@ async function probeWindowsRemote(ssh, explicitHermesPath = '') {
'}',
`$explicit=${explicit}`,
'if($explicit){Assert-NoReparse $explicit $false;$explicitPython=[IO.Path]::Combine([IO.Path]::GetDirectoryName($explicit), "python.exe");Assert-NoReparse $explicitPython $false}',
+ // HERMES_HOME is only trusted when it names a directory on the REMOTE: a stale User-scope
+ // value (older install.ps1 persisted one) or a client path leaked over SSH otherwise fails
+ // assertSafeRemoteHome as "Unsafe remote Hermes home" (#118988).
'$hermesHome=$env:HERMES_HOME',
- 'if(-not $hermesHome){$hermesHome=Join-Path $env:LOCALAPPDATA "hermes"}',
+ 'if(-not $hermesHome -or -not (Test-Path -LiteralPath $hermesHome -PathType Container)){$hermesHome=Join-Path $env:LOCALAPPDATA "hermes"}',
'Assert-NoReparse $hermesHome $true',
'$candidate=[IO.Path]::Combine($hermesHome, "hermes-agent\\venv\\Scripts\\hermes.exe")',
'$candidatePython=[IO.Path]::Combine([IO.Path]::GetDirectoryName($candidate), "python.exe")',