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(mirror): refuse credential-shaped binary names; own-property agent lookup

review23a7282b00c1
diff --git a/docs/mobile-chat-view.md b/docs/mobile-chat-view.md
index 05c19cadc..08a69c468 100644
--- a/docs/mobile-chat-view.md
+++ b/docs/mobile-chat-view.md
@@ -180,7 +180,13 @@ its own, so the agent-status mirror's `settings` block advertises them:
every name matches `^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$` — the BUILDER enforces this alphabet, because a
derived "name" can be a slice of a secret (`oauth2:ghp_…` from a git URL, a quoted env value, a
`${env:…}` template). **Empty = cannot be named honestly** (e.g. `bash -lc …`, or a name outside the
- alphabet): refuse, never guess. The phone still validates each name (`isPlainBinaryName`) and refuses otherwise.
+ alphabet): refuse, never guess.
+- Residual the alphabet cannot catch: the launch-command tokenizer cannot tell a runner option's
+ VALUE from the program, so `npx --registry-token ghp_… my-agent` would "name" the token. The builder
+ therefore also publishes `[]` for a name with a known credential prefix (`ghp_`, `gho_`, `ghu_`,
+ `ghs_`, `ghr_`, `github_pat_`, `AIza`, `sk-`, `xai-`, `glpat-`) or a high-entropy shape (≥ 32 chars,
+ ≥ 80% alphanumeric, letters AND digits). A heuristic: an unprefixed short secret can still pass, and a
+ real binary it catches is simply refused (`[]`). The phone still validates each name (`isPlainBinaryName`) and refuses otherwise.
- `baseAgent` is present only when it is a builtin id. Chat on SSH: only when it is `claude` (the only
harness the Swift parser reads); on relay the desktop decides (`canChat(capabilityAgentId(…))`).
- Never contains the raw launch command, args or env — they routinely hold API keys and proxy URLs,
diff --git a/src/core/mirror-custom-agents.test.ts b/src/core/mirror-custom-agents.test.ts
index c705d3524..f2df08724 100644
--- a/src/core/mirror-custom-agents.test.ts
+++ b/src/core/mirror-custom-agents.test.ts
@@ -75,6 +75,35 @@ describe('mirrorCustomAgents', () => {
expect(json).not.toContain(leak)
})
+ it('publishes [] for a name shaped like a credential, even inside the plain alphabet', () => {
+ // A runner option VALUE before the program can be taken as the program:
+ // `npx --registry-token ghp_… my-agent` names the token. The alphabet cannot catch that.
+ const tok36 = 'A1b2C3d4E5f6G7h8I9j0K1l2M3n4O5p6Q7r8'
+ const shaped = [
+ `ghp_${tok36}`, `gho_${tok36}`, `ghu_${tok36}`, `ghs_${tok36}`, `ghr_${tok36}`,
+ 'github_pat_11ABCDEF', 'AIzaSyD-short', 'sk-proj-abc', 'xai-abc123', 'glpat-abc123',
+ tok36 // no prefix, ≥32 chars, letters + digits: high-entropy
+ ]
+ const agents: CustomAgent[] = shaped.map((t, i) => ({
+ id: `custom:t${i}`, label: 'x', launchCmd: `npx --registry-token ${t} my-agent`
+ }))
+ const out = mirrorCustomAgents(agents)
+ expect(out.map((r) => r.binaries)).toEqual(shaped.map(() => []))
+ const json = JSON.stringify(buildFile({}, 1000, undefined, { customAgents: out }))
+ for (const t of shaped) expect(json).not.toContain(t)
+ })
+
+ it('keeps ordinary long names that do not look like a token', () => {
+ const agents: CustomAgent[] = [
+ { id: 'custom:a', label: 'a', launchCmd: 'my-very-long-descriptive-agent-cli-name' }, // no digits
+ { id: 'custom:b', label: 'b', launchCmd: 'agent2' }
+ ]
+ expect(mirrorCustomAgents(agents).map((r) => r.binaries)).toEqual([
+ ['my-very-long-descriptive-agent-cli-name'],
+ ['agent2']
+ ])
+ })
+
it('drops malformed records and non-custom ids, and a baseAgent that is not a builtin', () => {
const junk = [
null,
diff --git a/src/core/mirror-custom-agents.ts b/src/core/mirror-custom-agents.ts
index a8900a7b7..ee5002ae1 100644
--- a/src/core/mirror-custom-agents.ts
+++ b/src/core/mirror-custom-agents.ts
@@ -26,6 +26,22 @@ import type { MirrorCustomAgent } from './agent-status-mirror'
*/
const PLAIN_BINARY = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/
+/**
+ * Credential SHAPES that still fit the alphabet. `binaryFromLaunchCmd` cannot tell an option's
+ * VALUE from the program (`npx --registry-token ghp_… my-agent` names the token), so the builder
+ * also refuses anything that looks like a known token prefix, or a long high-entropy string. A
+ * heuristic, not a proof: its failure mode on a real binary is `[]` (the phone refuses), which is
+ * the safe direction.
+ */
+const TOKEN_PREFIXES = ['ghp_', 'gho_', 'ghu_', 'ghs_', 'ghr_', 'github_pat_', 'AIza', 'sk-', 'xai-', 'glpat-']
+
+function looksLikeCredential(name: string): boolean {
+ if (TOKEN_PREFIXES.some((p) => name.startsWith(p))) return true
+ if (name.length < 32) return false
+ const alnum = name.replace(/[^A-Za-z0-9]/g, '').length
+ return alnum / name.length >= 0.8 && /[A-Za-z]/.test(name) && /[0-9]/.test(name)
+}
+
/** Longest label we republish — a label is display text, not a payload. */
const LABEL_MAX = 200
@@ -51,7 +67,7 @@ export function mirrorCustomAgents(customAgents: readonly CustomAgent[] | null |
const binaries = binariesFor(c.id, [{ id: c.id, launchCmd, ...(base ? { baseAgent: base } : {}) }])
const label = typeof c.label === 'string' && c.label.trim() ? c.label.slice(0, LABEL_MAX) : c.id
// All-or-nothing: one unpublishable name means the derivation is not trustworthy as a whole.
- const plain = !!binaries && binaries.length > 0 && binaries.every((b) => PLAIN_BINARY.test(b))
+ const plain = !!binaries && binaries.length > 0 && binaries.every((b) => PLAIN_BINARY.test(b) && !looksLikeCredential(b))
out.push({ id: c.id, label, ...(base ? { baseAgent: base } : {}), binaries: plain ? [...binaries] : [] })
}
return out
diff --git a/src/shared/agents/pane-owner-predicate.test.ts b/src/shared/agents/pane-owner-predicate.test.ts
index 93167c9d0..2766bf132 100644
--- a/src/shared/agents/pane-owner-predicate.test.ts
+++ b/src/shared/agents/pane-owner-predicate.test.ts
@@ -203,6 +203,18 @@ describe('binariesFor', () => {
expect(binariesFor('custom:none', list)).toBeNull()
})
+ it('never resolves a prototype key as a builtin, and skips null/non-object records', () => {
+ expect(binariesFor('constructor')).toEqual(['constructor'])
+ expect(binariesFor('__proto__')).toEqual(['__proto__'])
+ expect(binariesFor('toString')).toEqual(['toString'])
+ const list = [null, 7, 'x', { id: 'custom:ok', launchCmd: 'ok-agent' }] as unknown as {
+ id: string
+ launchCmd: string
+ }[]
+ expect(binariesFor('custom:ok', list)).toEqual(['ok-agent'])
+ expect(binariesFor('custom:missing', list)).toBeNull()
+ })
+
it('never throws on a hand-edited non-string launch command — blank, same as the mirror builder', () => {
const list = [
{ id: 'custom:num', launchCmd: 42, baseAgent: 'claude' },
diff --git a/src/shared/agents/pane-owner-predicate.ts b/src/shared/agents/pane-owner-predicate.ts
index cd8ea0194..1d238bc03 100644
--- a/src/shared/agents/pane-owner-predicate.ts
+++ b/src/shared/agents/pane-owner-predicate.ts
@@ -180,9 +180,14 @@ export function binariesFor(
agentId: string,
customAgents?: readonly { id: string; launchCmd: string; baseAgent?: string }[]
): readonly string[] | null {
- const builtin = AGENT_BINARIES[agentId]
+ // Own property only: `constructor` / `__proto__` / `toString` must not resolve to a prototype
+ // member — an agent id is hand-editable (project.json, settings.json).
+ const builtin = Object.prototype.hasOwnProperty.call(AGENT_BINARIES, agentId)
+ ? AGENT_BINARIES[agentId]
+ : undefined
if (builtin) return builtin
- const custom = customAgents?.find((c) => c.id === agentId)
+ // Settings are hand-editable JSON: a null / non-object entry is skipped, never dereferenced.
+ const custom = customAgents?.find((c) => !!c && typeof c === 'object' && c.id === agentId)
if (custom) {
// A BLANK command with a base harness runs the base's own command — `resolveAgentConfig`
// (`shared/agents/custom-agent.ts`) resolves `launchCmd.trim() || base.launchCmd`, so the pane