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(ssh): stop refusing non-ASCII home directories on remote hosts
enesf1eaa5980e82
diff --git a/src/main/remote-ssh/remote-hooks.test.ts b/src/main/remote-ssh/remote-hooks.test.tsindex 9053fed12..54162f482 100644--- a/src/main/remote-ssh/remote-hooks.test.ts+++ b/src/main/remote-ssh/remote-hooks.test.ts@@ -1,5 +1,5 @@import { describe, expect, it, vi } from 'vitest'-import { RemoteHooks } from './remote-hooks'+import { RemoteHooks, isSafeRemoteHome } from './remote-hooks'const conn = { host: 'h', user: 'u' }@@ -590,4 +590,76 @@ describe('RemoteHooks.setup — the host $HOME is data, not truth', () => {// Only the $HOME probe itself ran — nothing interpolated the answer.expect(calls).toHaveLength(1)})++ // The counterpart to the refusal above, and the reason this predicate was rewritten: a home+ // directory named in a non-ASCII script is a NORMAL home, and the old allowlist turned it into a+ // total, silent loss of every remote hook for that user.+ it('installs hooks for a host whose $HOME is not spelled in ASCII', async () => {+ const { rh, calls } = harness({ responses: { 'printf %s "$HOME"': '/home/gökhan' } })+ const res = await rh.setup('p1', conn, '/s.sock', { port: 51234, token: 'tok', version: '1' })+ expect(res?.endpointPath).toBe('/home/gökhan/.nodeterm/hook-endpoint-p1.env')+ const joined = calls.map((c) => c.args.join(' '))+ expect(joined.some((j) => j.includes('cat > /home/gökhan/.claude/settings.json'))).toBe(true)+ })+})++describe('isSafeRemoteHome', () => {+ // Every one of these is somebody's actual home directory. A predicate that rejects any of them+ // costs that user every status badge, the context meter and every subagent card, silently.+ const REAL_HOMES = [+ '/home/user',+ '/Users/First Last', // macOS full-name accounts are ordinary+ '/home/josé',+ '/home/müller',+ '/home/gökhan',+ '/Users/山田',+ '/home/пользователь',+ '/home/user.name',+ '/home/user-name',+ '/home/user_name',+ '/var/services/homes/user', // Synology DSM+ '/data/data/com.termux/files/home', // Termux+ `/home/${'a'.repeat(4000)}`+ ]+ it.each(REAL_HOMES)('accepts %s', (home) => {+ expect(isSafeRemoteHome(home)).toBe(true)+ })++ // `$HOME` is interpolated into remote command lines, several still unquoted, so each of these+ // would be live shell on a host we are logged into as the user.+ const ATTACKS: [string, string][] = [+ ['embedded newline', '/home/u\ntouch /tmp/pwn'],+ ['carriage return', '/home/u\rtouch /tmp/pwn'],+ ['NUL', '/home/u\u0000/x'],+ ['tab (IFS)', '/home/u\tx'],+ ['line separator', '/home/u\u2028x'],+ ['command chain', '/home/u; rm -rf /'],+ ['command substitution', '/home/$(id)'],+ ['backtick substitution', '/home/`id`'],+ ['single quote', "/home/u'; id; :'"],+ ['double quote', '/home/u"x'],+ ['backslash', '/home/u\\x'],+ ['variable expansion', '/home/$USER'],+ ['pipe', '/home/u | id'],+ ['background', '/home/u & id'],+ ['redirection', '/home/u > /etc/passwd'],+ ['subshell', '/home/(u)'],+ ['brace expansion', '/home/{a,b}'],+ ['glob', '/home/*'],+ ['relative traversal', '../..'],+ ['relative', 'home/user'],+ ['tilde', '~/x'],+ ['empty', ''],+ ['leading space', ' /home/u'],+ ['trailing space', '/home/u '],+ ['over the ceiling', `/home/${'a'.repeat(5000)}`]+ ]+ it.each(ATTACKS)('rejects %s', (_label, home) => {+ expect(isSafeRemoteHome(home)).toBe(false)+ })++ it('rejects a non-string without throwing', () => {+ expect(isSafeRemoteHome(undefined as unknown as string)).toBe(false)+ expect(isSafeRemoteHome(null as unknown as string)).toBe(false)+ })})diff --git a/src/main/remote-ssh/remote-hooks.ts b/src/main/remote-ssh/remote-hooks.tsindex c6e44d895..427a51fcd 100644--- a/src/main/remote-ssh/remote-hooks.ts+++ b/src/main/remote-ssh/remote-hooks.ts@@ -57,6 +57,26 @@ export interface RemoteRunner {/** Generous ceiling on a host-reported `$HOME` — longer than any real path, short enough to bound. */const REMOTE_HOME_MAX = 4096+/**+ * Every character that is live shell syntax at this file's `$HOME` interpolation sites, plus+ * every control character. It is a DENYLIST on purpose - see `isSafeRemoteHome`.+ *+ * - C0 (u0000-u001f) and C1 (u007f-u009f) controls: \n / \r are command+ * separators, \t is IFS, NUL truncates. U+2028/U+2029 are not shell-special but are+ * line breaks everywhere else (logs, JSON) and no real path holds one.+ * - Quote and expansion characters: single quote, double quote, backtick, $ and \\.+ * `$(...)` and backticks are command substitution.+ * - `;&|<>(){}` - separators, pipes, redirections, subshells, brace expansion.+ * - `*?[]` - globs; a star in the path makes `mkdir -p` reach a directory we never named.+ * - `!#` - history expansion and comments.+ *+ * The class is written with \u ESCAPES, never raw bytes: a source file carrying a literal+ * NUL is skipped in silence by git, grep and ripgrep (this repo has lost two files to that).+ *+ * NOT here, deliberately: every letter on earth. That was the bug.+ */+const REMOTE_HOME_UNSAFE = /[\u0000-\u001f\u007f-\u009f\u2028\u2029'"`$\\;&|<>(){}[\]*?!#]/+/*** Is a host-reported `$HOME` safe to build remote commands from?*@@ -65,11 +85,29 @@ const REMOTE_HOME_MAX = 4096* newline is therefore a command separator, and one holding `$(…)`/backticks is a substitution, on* a host we are running as the user. A host can set `$HOME` to whatever it likes.*- * Deliberately far narrower than "what a filesystem allows": ordinary path characters only. The- * cost of a false rejection is fail-open (no per-node token → `legacy`, the designed state; or, in- * `setup`, no hooks at all — which is why the rejection is LOUD there), and the cost of a false- * acceptance is remote code execution. A host whose home directory contains a non-ASCII character- * is refused by that trade, which is the known and accepted price.+ * THE SHAPE MATTERS. This used to be an allowlist — `/^[\w./ -]+$/` — and `\w` in JavaScript is+ * `[A-Za-z0-9_]`, always, with or without the `u` flag; there is no switch that widens it. So+ * `/home/josé`, `/home/gökhan`, `/Users/山田` and every other home directory whose owner does not+ * spell their name in ASCII was judged "not a plain path". The consequence was total and silent for those+ * users: `setup` refused, so no status badges, no context meter, no subagent cards, on every SSH+ * host they own — the exact fail-open-in-silence class this file has been bitten by twice, this+ * time aimed squarely at non-English users. An allowlist of LETTERS can only ever be a list of+ * the alphabets its author happened to think of.+ *+ * So it enumerates what is DANGEROUS instead (`REMOTE_HOME_UNSAFE`), which is a closed set: shell+ * metacharacters and control characters. Anything else — any script's letters, spaces (macOS+ * `/Users/First Last` is ordinary), dots, dashes, underscores — is just a path. It must also be+ * ABSOLUTE: a relative answer would build relative remote paths against whatever cwd the exec+ * channel lands in, and `../..` stops being interesting the moment `/` is required up front.+ *+ * A single quote stays refused even though `posixQuote` handles it correctly (it closes, escapes+ * and reopens: `o'brien` → `'o'\''brien'`, which round-trips byte-for-byte through /bin/sh).+ * Correct quoting is no help at the sites that do not quote at all, and those are the sites this+ * value reaches.+ *+ * A space is accepted here because it is not injection, but note that the unquoted sites above+ * would still WORD-SPLIT it (`mkdir -p /Users/First Last/.nodeterm` makes two directories). That+ * predates this predicate and is unchanged by it; quoting those sites is the real fix.** It judges the EXACT string the caller holds — leading/trailing whitespace is a rejection, not* something quietly stripped (same rule as `isSafeRemoteGrokHome`): trimming here would return@@ -80,7 +118,9 @@ export function isSafeRemoteHome(home: string): boolean {typeof home === 'string' &&home.length > 0 &&home.length <= REMOTE_HOME_MAX &&- /^[\w./ -]+$/.test(home)+ home.startsWith('/') &&+ home === home.trim() &&+ !REMOTE_HOME_UNSAFE.test(home))}