Skip to content

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.

fix(ssh): reject non-absolute upload localPath (argv flag-smuggling guard)

enes51e06ffa8ba8
diff --git a/src/main/remote-ssh/ssh-project.test.ts b/src/main/remote-ssh/ssh-project.test.ts
index 917952850..9f52553f8 100644
--- a/src/main/remote-ssh/ssh-project.test.ts
+++ b/src/main/remote-ssh/ssh-project.test.ts
@@ -111,4 +111,21 @@ describe('SshProjectManager', () => {
const { mgr } = makeMgr()
expect(await mgr.uploadFile('nope', '/x', 'x')).toBeNull()
})
+
+ it('uploadFile rejects a non-absolute localPath (argv flag-smuggling guard)', async () => {
+ const scpCalls: string[][] = []
+ const run = vi.fn(async (args: string[]) =>
+ args.join(' ').includes('printf %s') ? { code: 0, stdout: '/home/u' } : { code: 0, stdout: '' }
+ )
+ const runScp = vi.fn(async (args: string[]) => { scpCalls.push(args); return { code: 0 } })
+ const mgr = new SshProjectManager({
+ userDataDir: '/ud', spawnMaster: vi.fn(() => ({ kill: vi.fn(), on: vi.fn() })),
+ run, runScp, getHook: () => ({ port: 1, token: 't', version: '1' }), onStatus: vi.fn()
+ })
+ await mgr.connect('p1', conn, '/srv/repo')
+ // A leading `-` would be parsed by scp as an OPTION (e.g. -oProxyCommand=…) → reject; also relative.
+ expect(await mgr.uploadFile('p1', '-oProxyCommand=touch /tmp/pwned', 'x.png')).toBeNull()
+ expect(await mgr.uploadFile('p1', 'relative/path.png', 'x.png')).toBeNull()
+ expect(scpCalls).toHaveLength(0) // scp never invoked for an unsafe localPath
+ })
})
diff --git a/src/main/remote-ssh/ssh-project.ts b/src/main/remote-ssh/ssh-project.ts
index c5f0b4caa..540a71d17 100644
--- a/src/main/remote-ssh/ssh-project.ts
+++ b/src/main/remote-ssh/ssh-project.ts
@@ -195,6 +195,11 @@ export class SshProjectManager {
async uploadFile(projectId: string, localPath: string, fileName: string): Promise<string | null> {
const c = this.conns.get(projectId)
if (!c) return null
+ // `localPath` is a renderer string passed straight to scp as a positional arg. A value starting
+ // with `-` (e.g. `-oProxyCommand=…`) would be parsed by scp as an OPTION (argv flag smuggling →
+ // RCE), not a file. A real OS file drop is always an absolute path, so require one here — this
+ // rejects `-`-prefixed, relative, and empty paths and fully closes the flag-smuggling vector.
+ if (!localPath.startsWith('/')) return null
try {
let home = c.remoteHome
if (!home) {