Open source Grok Bot alternative, Bring your own agent and subscription: message Claude Code, Codex, Gemini CLI, Cursor, Copilot and 40+ AI agents as bots on your own computer, from iPhone, Mac, Windows, Linux or terminal. Agent-agnostic and free. Also a Muse and Dots alternative. Built in Rust.
Rust acpagent-client-protocolai-agentsai-assistantclaudeclaude-codecodexcoding-agentscursorgeminigemini-cligrok-bot-alternativeiosiphonelinuxmacosmcpopen-sourcerustself-hosted
fix(desktop): verify Windows SSH tunnel peer ownership (#266)
Sean Ferguson367ffe5a522d
diff --git a/apps/desktop/src/main/ssh-process.ts b/apps/desktop/src/main/ssh-process.tsindex 729539d6..f52c25cb 100644--- a/apps/desktop/src/main/ssh-process.ts+++ b/apps/desktop/src/main/ssh-process.ts@@ -72,7 +72,16 @@ function powershell(script: string) {export function listenerCommand(pid: number, port: number) {if (!Number.isSafeInteger(pid) || pid <= 0 || !Number.isInteger(port) || port < 1 || port > 65535) throw new Error('Invalid listener')- return `Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort ${port} -State Listen -ErrorAction SilentlyContinue | Where-Object { $_.OwningProcess -eq ${pid} } | ForEach-Object { $_.OwningProcess }`+ // Some Windows builds misreport listening sockets' State. Verify the owner of+ // an actual loopback connection using its exact reverse tuple instead.+ return `$ErrorActionPreference='Stop'+$client = [System.Net.Sockets.TcpClient]::new()+try {+ $client.Connect('127.0.0.1', ${port})+ $peer = $client.Client.LocalEndPoint.Port+ Get-NetTCPConnection -LocalAddress 127.0.0.1 -LocalPort ${port} -RemoteAddress 127.0.0.1 -RemotePort $peer -ErrorAction Stop |+ Where-Object { $_.OwningProcess -eq ${pid} } | ForEach-Object { $_.OwningProcess }+} finally { $client.Dispose() }`}/** Never send the host token until the listener is owned by the exact ssh child. */diff --git a/apps/desktop/src/shared/ssh-platform.test.ts b/apps/desktop/src/shared/ssh-platform.test.tsindex bded7c40..a31f860e 100644--- a/apps/desktop/src/shared/ssh-platform.test.ts+++ b/apps/desktop/src/shared/ssh-platform.test.ts@@ -1,6 +1,7 @@import assert from 'node:assert/strict'+import { once } from 'node:events'import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'-import { createServer } from 'node:net'+import { createConnection, createServer } from 'node:net'import { tmpdir } from 'node:os'import { join } from 'node:path'import test from 'node:test'@@ -89,3 +90,22 @@ test('listener ownership accepts the listening process and rejects another proceassert.throws(() => listenerCommand(123, -1))assert.throws(() => listenerCommand(NaN, 19222))})++test('listener ownership rejects an outgoing socket and a closed port', async () => {+ const server = createServer((socket) => socket.resume())+ await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve))+ const address = server.address()+ assert.ok(address && typeof address === 'object')+ const client = createConnection({ host: '127.0.0.1', port: address.port })+ try {+ await once(client, 'connect')+ assert.ok(client.localPort)+ const outgoing = await sshListens(process.pid, client.localPort)+ assert.equal(outgoing, false)+ } finally {+ client.destroy()+ await new Promise<void>((resolve) => server.close(() => resolve()))+ }+ const closed = await sshListens(process.pid, address.port)+ assert.equal(closed, false)+})