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.

docs(security): the latch catches a mistake, not an attacker

Claude Codec0e38a07357c
diff --git a/docs/node-identity.md b/docs/node-identity.md
index e0bff9161..b94e27e77 100644
--- a/docs/node-identity.md
+++ b/docs/node-identity.md
@@ -75,9 +75,21 @@ every remote curl reads its header from stdin via `curl --config -`) and that th
### What the design is trying to buy
-Turning **"any session on this machine can act as any node, by default"** into **"a session can act
-as another node only if it deliberately goes and harvests that node's credential."** That is a real
-change in default posture and a real reduction in blast radius. It is not isolation.
+Turning **"any session on this machine can act as any node, by default"** into **"a session that
+wants to act as another node has to do something deliberate about it."** That is a real change in
+default posture and a real reduction in blast radius. It is not isolation, and the qualifier is doing
+work — *deliberate* means different things per route:
+
+- On the routes that demand `verified` — `/codex-thread/{start,bind}`, and every `/control/*`
+ mutation once the cutoff passes — it means **harvesting that node's token file** off the disk.
+- On `/hook/*` it means nothing at all: a tokenless POST naming any node is accepted forever, by
+ contract (invariant 2).
+- On `/control/list` and `/context-link/*` it means **inventing a `kid`**. A made-up kid is a
+ *foreign* kid, therefore `legacy`, therefore never caught by the latch (invariant 3) — see the
+ latch warning below, which is pinned by a test.
+
+What actually went away is the *accident*: the credential no longer falls out of the process table
+into every account on the machine.
## What this does NOT fix
@@ -104,8 +116,12 @@ over-trusts it.
host+user (two desktops on a shared deploy account) mint with different secrets and overwrite each
other's files. The loser's sessions then present a foreign `kid`, which reads as `legacy` — never
as another node, never as `forged`. The cost is a silent drop to the fail-open state, not a
- mis-verification. `node-tokens/<kid>/<id>` would close it and needs no client change; see the
- `writeNodeTokens` doc comment.
+ mis-verification — **but only until the cutoff.** From 2026-10-13 `legacy` is a refusal for every
+ `/control/*` mutation, so the loser does not degrade gracefully any more: it loses remote canvas
+ control outright, silently, on a date nobody will connect to the symptom.
+ `node-tokens/<kid>/<id>` would close it and needs no client change; see the `writeNodeTokens` doc
+ comment. It is also the only hardening that would give the trust-on-first-proof latch any teeth —
+ see the latch warning below.
### Rotation, honestly
@@ -232,9 +248,38 @@ managed hook script presents the header, and the boot sweep materialises a token
persisted node — so a live Claude node is typically latched **within seconds of app start**. From
that moment, a tokenless caller naming it gets a hard 403, today, with no grace and no date.
-That is intentional (a session that could authenticate and suddenly cannot is exactly the case worth
-refusing), but it means the mitigations against *stranding* a live node are what make the feature
-shippable, not the window:
+### ⚠ …and the latch is not a defence against an attacker
+
+**It catches a MISTAKE — a session that silently stopped presenting its token — and nothing else.**
+Do not re-derive a stronger claim from the code; this one is measured against the real hook server
+and pinned by a named test (`hook-identity-enforcement.test.ts`, *"an invented kid is admitted — the
+latch is not an adversary boundary"*).
+
+The probe: send `X-Nodeterm-Node-Token: AAAAAAAA.BBBB…` — eight arbitrary characters, a dot, an
+arbitrary tail. Nothing about it is ours, which is exactly the point: the `kid` does not match this
+instance's, so `verifyNodeToken` calls it **foreign**, therefore `legacy`, and invariant 3 says a
+foreign kid never proves and is never caught by the latch. The latch simply does not apply. That
+caller reaches `/control/list` and **every** `/context-link/*` verb as a latched victim node, on both
+sides of the cutoff, and is handed the victim's rendered transcript.
+
+**This is unavoidable and it is correct.** Invariant 3 requires a foreign kid to be admitted, or
+cross-instance failover dies the day a second instance appears — and the attacker is the one who
+chooses the kid, so there is no version of "judge the foreign kid" that an attacker cannot step
+around. Anyone who can set the header can present an unjudgeable one, and the app-wide bearer is all
+it takes to set the header. So: the latch is a good bug-catcher and worth keeping; it is not a
+boundary, and neither is the dated cutoff (the same probe walks past both).
+
+**The real hardening, if it is ever wanted.** Scope the remote token dir as
+`node-tokens/<kid>/<nodeId>` (already sketched in `writeNodeTokens`' own doc comment). The *only*
+scenario the foreign-kid escape exists for is two instances sharing one host account overwriting
+each other's flat token dir. Remove that overwrite and a foreign kid stops being a legitimate state,
+at which point it can be judged and the latch acquires the teeth this section says it does not have.
+
+### Stranding is the cost the latch actually charges
+
+Refusing a proven node the instant it stops presenting a token is intentional, but it is also the one
+way this feature can kill a live session outright. These are what pay that down — they are what make
+the latch shippable, not the window:
- every token sweep releases the latch (collision refusal, delete/re-create, remote refusal);
- the clock clamp;
@@ -316,3 +361,10 @@ fail-open state.
| Clock implausibly far ahead | Window stays open (`isStrictInstant`) |
| Hook handler throws | Still 204 |
| `forged` | **The one fail-closed case.** 403, every route, no prose |
+
+ **Every row that lands on `legacy` is only fail-OPEN until 2026-10-13.** On and after the cutoff
+ `legacy` is a refusal for every `/control/*` mutation, so a degradation nobody notices today
+ becomes a node that cannot drive the canvas at all — e.g. two instances sharing one remote host
+ account overwrite each other's token dir (§What this does NOT fix) and the loser loses remote
+ canvas control outright, on a date nobody will connect to the symptom. Each `legacy` row is a
+ thing to fix *before* the date, not a permanently safe landing.
diff --git a/src/core/agents/hook-identity-enforcement.test.ts b/src/core/agents/hook-identity-enforcement.test.ts
index 4d1e0608f..827147e3a 100644
--- a/src/core/agents/hook-identity-enforcement.test.ts
+++ b/src/core/agents/hook-identity-enforcement.test.ts
@@ -26,6 +26,7 @@ import {
NODE_IDENTITY_STRICT_AFTER,
TOLERANT_CONTROL_VERBS
} from './node-identity-policy'
+import { CONTEXT_LINK_VERBS } from '../context-link-render'
import { initPlatform, resetPlatformForTests } from '../platform'
import { fakePlatform } from '../platform-fake'
@@ -270,6 +271,85 @@ describe('a foreign kid', () => {
})
})
+/**
+ * THE COUNTER-CLAIM, PINNED. Three places in this series used to describe the latch as the feature's
+ * security boundary. It is not one, and the difference matters enough to spend a test on: someone
+ * reading `controlPolicy` alone will re-derive the stronger claim, because the table really does say
+ * `legacy + latched → refuse`.
+ *
+ * What that table cannot show is who gets to be `legacy`. `verifyNodeToken` reads a token whose
+ * `kid` is not ours as FOREIGN ⇒ `legacy`, and invariant 3 requires a foreign kid to never prove and
+ * never latch (or the cross-instance failover dies the day a second instance exists). The attacker
+ * chooses the kid. So a token made of arbitrary characters is admitted for a latched victim node,
+ * while the honest tokenless caller for that same node is refused.
+ *
+ * The behaviour below is CORRECT and must not be "fixed" — the only hardening that would change it
+ * is `node-tokens/<kid>/<nodeId>` (see `writeNodeTokens`), which removes the reason a foreign kid
+ * has to be admitted at all. This test exists so the false claim cannot come back.
+ */
+describe('an invented kid is admitted — the latch is not an adversary boundary', () => {
+ // Eight arbitrary characters, a dot, an arbitrary tail: the wire shape, none of the substance.
+ // Nothing derives it, nothing on this machine ever held it.
+ const INVENTED = 'AAAAAAAA.BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'
+
+ it('is not a token this instance could ever mint, and is not `forged` either', async () => {
+ // Sanity, so the probe below cannot pass for the boring reason that it accidentally IS a token.
+ expect(INVENTED).not.toBe(nodeAuthToken(SECRET, 'n-invented'))
+ // `forged` would be a 403 on /hook/* — the whole point is that a foreign kid is not judgeable,
+ // so it lands on the fail-open verdict instead.
+ expect((await hookEvent('n-invented', INVENTED)).status).toBe(204)
+ expect(hookServer.isNodeProven('n-invented')).toBe(false)
+ })
+
+ for (const [when, clock] of [
+ ['during the window', IN_WINDOW],
+ ['after the cutoff', PAST_CUTOFF]
+ ] as const) {
+ it(`walks past the latch into /control/list ${when}, as the victim node`, async () => {
+ hookServer.setIdentityClockForTests(() => clock)
+ const node = `n-invented-list-${when.replace(/\s/g, '-')}`
+ // Arm the latch for real: the victim proves itself with this instance's own token.
+ expect((await hookEvent(node, nodeAuthToken(SECRET, node))).status).toBe(204)
+ expect(hookServer.isNodeProven(node)).toBe(true)
+ // The honest tokenless caller is refused — this is the latch working as designed…
+ expect((await control('list', node)).status).toBe(403)
+ expect(controlCalls).toEqual([])
+ // …and the attacker, who simply made a kid up, is not.
+ const res = await control('list', node, INVENTED)
+ expect(res.status).toBe(200)
+ expect(controlCalls).toEqual([{ verb: 'list', nodeId: node }])
+ })
+
+ it(`reads EVERY context-link verb for a latched victim ${when}`, async () => {
+ hookServer.setIdentityClockForTests(() => clock)
+ const node = `n-invented-ctx-${when.replace(/\s/g, '-')}`
+ expect((await hookEvent(node, nodeAuthToken(SECRET, node))).status).toBe(204)
+ // Tokenless gets the refusal sentence instead of the transcript.
+ expect((await contextLink('transcript', node)).status).toBe(200)
+ expect(contextCalls).toEqual([])
+
+ // Every verb the route actually serves, not a hand-picked one: a verb added later must be
+ // covered by this claim too, or the doc it pins goes quietly out of date.
+ for (const verb of CONTEXT_LINK_VERBS) {
+ const res = await contextLink(verb, node, INVENTED)
+ expect(res.status, verb).toBe(200)
+ // The rendered transcript itself — not the refusal prose. This is the leak.
+ expect(await res.text(), verb).toContain('the linked transcript')
+ }
+ expect(contextCalls).toEqual(CONTEXT_LINK_VERBS.map((verb) => ({ verb, nodeId: node })))
+ })
+ }
+
+ it('buys nothing extra on a MUTATION after the cutoff — that much the cutoff does hold', async () => {
+ // The escape is bounded: `legacy` is still refused for mutations past the date, invented kid or
+ // not. What the invented kid defeats is the LATCH, i.e. the tolerant bucket and the window.
+ hookServer.setIdentityClockForTests(() => PAST_CUTOFF)
+ const res = await control('open-terminal', 'n-invented-mutation', INVENTED)
+ expect(res.status).toBe(403)
+ expect(controlCalls).toEqual([])
+ })
+})
+
describe('the latch is memory, not state', () => {
it('leaves no trace of a proven node anywhere under the data dir', async () => {
expect((await hookEvent('n-nopersist', nodeAuthToken(SECRET, 'n-nopersist'))).status).toBe(204)
diff --git a/src/core/agents/node-identity-policy.test.ts b/src/core/agents/node-identity-policy.test.ts
index 9b74ca26b..c8e9f38ee 100644
--- a/src/core/agents/node-identity-policy.test.ts
+++ b/src/core/agents/node-identity-policy.test.ts
@@ -168,9 +168,14 @@ describe('controlPolicy', () => {
).toBe('allow-with-warning')
})
- it('does not disarm the LATCH, which is the actual security boundary here', () => {
+ it('relaxes only the DATE — the latch and `forged` are untouched by it', () => {
// The clamp only ever relaxes the DATE. A node that has proven itself is still refused when
// an unverified caller turns up for it — that is what makes the clamp cheap.
+ //
+ // NOT because the latch is a security boundary: it is not, and this suite must not be read
+ // as saying so. The latch catches a MISTAKE (a session that stopped presenting its token);
+ // an attacker invents a `kid`, which is FOREIGN, which is `legacy`, which never latches by
+ // invariant 3. See `hook-identity-enforcement.test.ts` → "an invented kid is admitted".
expect(controlPolicy({ verdict: 'legacy', proven: true, verb: MUTATION, now: wayAhead })).toBe(
'refuse'
)
diff --git a/src/core/agents/node-identity-policy.ts b/src/core/agents/node-identity-policy.ts
index 304ff1873..052de0c15 100644
--- a/src/core/agents/node-identity-policy.ts
+++ b/src/core/agents/node-identity-policy.ts
@@ -50,11 +50,19 @@ const STRICT_DATE = NODE_IDENTITY_STRICT_DATE
* nothing on its own. Since the two are indistinguishable, the tie is broken by which mistake is
* worse — and the whole series fails OPEN by design, so the answer is to keep the window open.
*
- * That costs almost nothing, because **the cutoff is not the security boundary — the latch is.**
- * Trust on first proof refuses an unverified caller for a node that has ever proven itself,
- * immediately, on both sides of the cutoff and regardless of this clamp. What the cutoff governs is
- * only the population that has NEVER proven anything, i.e. exactly the pre-token sessions the
- * warning window exists for, and fail-open is that population's designed state.
+ * That costs almost nothing, and it is worth being exact about WHY, because the obvious reason is
+ * false. **Neither the cutoff nor the latch is a boundary against an attacker.** The latch protects
+ * against a MISTAKE — a session that silently stopped presenting its token. It cannot protect
+ * against an adversary, because an adversary picks the `kid`: a made-up `kid` is a FOREIGN kid,
+ * which invariant 3 requires to be `legacy` and never latched (or cross-instance failover dies), so
+ * an invented token walks past the latch AND the cutoff into `/control/list` and every
+ * `/context-link/*` read. Measured against the real server and pinned in
+ * `hook-identity-enforcement.test.ts` ("an invented kid is admitted"); see docs/node-identity.md.
+ *
+ * So the clamp is cheap for a smaller and more honest reason: what it relaxes is only the
+ * population that has NEVER proven anything, i.e. exactly the pre-token sessions the warning window
+ * exists for, and fail-open is that population's designed state. It relaxes the DATE and nothing
+ * else — `forged` and the latch are untouched by it.
*
* Two years, because that is comfortably longer than the upgrade population survives (tmux sessions
* and un-updated installs do not last it out) and comfortably shorter than the clock skews that