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(security): send the hook bearer to the remote probe over stdin, not argv

enes20b6b02ebbf6
diff --git a/src/main/remote-ssh/remote-hooks.test.ts b/src/main/remote-ssh/remote-hooks.test.ts
index 54162f482..7968e0bbd 100644
--- a/src/main/remote-ssh/remote-hooks.test.ts
+++ b/src/main/remote-ssh/remote-hooks.test.ts
@@ -130,8 +130,26 @@ describe('RemoteHooks.setup', () => {
expect(joined.filter((j) => j.includes('-O forward')).length).toBe(2)
// The retry clears our own possibly-registered spec before rebinding.
expect(joined.some((j) => j.includes('-O cancel'))).toBe(true)
- // The verify curl runs on the HOST through the sock with the fresh token.
- expect(joined.some((j) => j.includes('--unix-socket') && j.includes('x-nodeterm-hook-token: tok'))).toBe(true)
+ // The verify curl runs on the HOST through the sock, reading the fresh token off stdin.
+ const probes = calls.filter((c) => c.cmd.includes('--unix-socket') && c.cmd.includes('%{http_code}'))
+ expect(probes).toHaveLength(2)
+ for (const p of probes) expect(p.stdin).toBe('header = "x-nodeterm-hook-token: tok"\n')
+ })
+
+ it('never puts the hook bearer on the remote probe command line', async () => {
+ // A remote command line is argv on BOTH ends: anything here is readable in the host's `ps` by
+ // every other user on that host, for as long as the curl lives. The bearer therefore rides
+ // stdin (`curl --config -`), which is the whole point of this probe's shape.
+ const secret = 'b3ar3r-9f2c-4a71-8e05-c0ffee000001'
+ const { rh, calls } = harness()
+ const res = await rh.setup('p1', conn, '/s.sock', { port: 51234, token: secret, version: '1' })
+ expect(res).not.toBeNull()
+ // Not one ARGUMENT of any ssh child command mentions it — not the probe, not anything else.
+ for (const c of calls) for (const a of c.args) expect(a).not.toContain(secret)
+ // ...and the probe still presents it, over stdin, as a curl config header.
+ const probe = calls.find((c) => c.cmd.includes('%{http_code}'))
+ expect(probe?.cmd).toContain('--config -')
+ expect(probe?.stdin).toBe(`header = "x-nodeterm-hook-token: ${secret}"\n`)
})
it('refuses to advertise a tunnel that never verifies — no endpoint file, null result', async () => {
diff --git a/src/main/remote-ssh/remote-hooks.ts b/src/main/remote-ssh/remote-hooks.ts
index 427a51fcd..cda51ef66 100644
--- a/src/main/remote-ssh/remote-hooks.ts
+++ b/src/main/remote-ssh/remote-hooks.ts
@@ -773,6 +773,22 @@ export class RemoteHooks {
* managed hook script uses, run ON the host. `000`/curl-fail = the listener's target is dead
* (a stale forward from a previous run). No `payload` field is sent, so the server records
* nothing (its listener path needs one).
+ *
+ * THE BEARER GOES ON STDIN, NEVER ARGV. This used to send `-H 'x-nodeterm-hook-token: <token>'`
+ * on the curl command line — and a remote command line is argv on BOTH ends: for as long as that
+ * curl lives, every OTHER user on the host can read the app-wide hook bearer out of `ps` /
+ * `/proc/<pid>/cmdline`. It is the same leak already measured and closed on the local side (the
+ * tmux `-e` channel), just pointed at someone else's machine. `curl --config -` reads options
+ * from stdin, where `header = "..."` sets the same header with nothing to see in the process
+ * table; `codex-identity-proxy.ts` already uses this exact idiom, and the runner already writes
+ * stdin (the endpoint-file write does).
+ *
+ * There is deliberately NO argv fallback for a curl too old for `--config` (it has had it since
+ * the 1990s): a fallback that puts the token back on argv would simply undo this. The probe
+ * failing is already a designed state — an unverified tunnel means remote agents run without
+ * hooks, loudly warned — and that is strictly better than leaking the bearer.
+ *
+ * What counts as SUCCESS is unchanged: exit 0 and a body of exactly `204`.
*/
private async verifyTunnel(
conn: SshConnection,
@@ -788,8 +804,15 @@ export class RemoteHooks {
// effect of sending no payload; the identity label on `/hook/*` would have started judging
// it there. `nodeId=verify` is kept in the body only so an OLDER desktop's script and this
// one send the same bytes; the route reads nothing.
- `-H ${posixQuote(`x-nodeterm-hook-token: ${token}`)} http://localhost/verify --data nodeId=verify`
- const r = await this.r.run(childArgs(conn, controlPath, cmd))
+ `--config - http://localhost/verify --data nodeId=verify`
+ // A curl config file's double-quoted value understands backslash escapes, so the token is
+ // escaped for it. Today's bearer is a `randomUUID()` (hex + dashes) and cannot contain
+ // either character — the escaping is here so that stays true if the mint ever changes.
+ const header = token.replace(/\\/g, '\\\\').replace(/"/g, '\\"')
+ const r = await this.r.run(
+ childArgs(conn, controlPath, cmd),
+ `header = "x-nodeterm-hook-token: ${header}"\n`
+ )
return r.code === 0 && r.stdout.trim() === '204'
} catch {
return false