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(relay-pop): capture the prover's secret at creation; close the C1 mirror minors
review64cab3ed5203
diff --git a/src/core/relay/relay-pop.test-server.ts b/src/core/relay/relay-pop.test-server.tsindex 109a9a0a3..a57dafc00 100644--- a/src/core/relay/relay-pop.test-server.ts+++ b/src/core/relay/relay-pop.test-server.ts@@ -4,6 +4,11 @@// backend does (docs/hosted-team-relay.md), so a client that proves something the backend would// refuse goes red here instead of in production. The hostId hash is computed inline rather than via// ./relay-id: a mirror of the BACKEND must not silently follow a drift in the client's own derivation.+//+// Deliberately NOT mirrored: the backend's cap on its used-nonce set (50 000 entries; when full it+// sweeps the expired nonces, then evicts the oldest). `used` below is an unbounded Set. A test issues+// a handful of challenges, nowhere near the cap, and what a client test needs from the mirror is the+// replay refusal itself; the cap only decides which very old nonce becomes replayable under load.import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto'import nacl from 'tweetnacl'import type { PopPurpose } from './relay-pop'@@ -70,7 +75,11 @@ export function createTestPopServer(return {issue(hostPublicKeyB64, purpose) {const hostPub = decodeHostKey(hostPublicKeyB64)- // The backend answers null (→ 400) here; a test that sends a bad key should fail loudly.+ // The backend answers null (→ 400) here; this throws instead. Called inside a fetch fake (where+ // every client test calls it), the throw becomes a rejected fetch, which the client reads as a+ // transient network failure (`network` on the Server Edition mint, `null` on the desktop mint,+ // 'drop' on push), NOT a loud error: a test that expects success still fails, but on its own+ // assertion, not here.if (!hostPub || !PURPOSES.includes(purpose)) throw new Error('relay-pop test server: bad host key or purpose')const nonce = b64u(opts.nonce ?? randomBytes(16))const exp = nowS() + CHALLENGE_TTL_Sdiff --git a/src/core/relay/relay-pop.test.ts b/src/core/relay/relay-pop.test.tsindex 5a41b87d1..876815b56 100644--- a/src/core/relay/relay-pop.test.ts+++ b/src/core/relay/relay-pop.test.ts@@ -17,6 +17,15 @@ describe('relay-pop: the shared vector (byte contract with nodeterm-server)', ()const s = createTestPopServer(vector.popSecret, { now: () => (vector.cases[0].exp - 60) * 1000, nonce: Buffer.from(vector.nonce, 'base64url') })expect(s.issue(vector.hostPublicKeyB64, 'host-token')).toEqual({ challenge: vector.cases[0].challenge, serverPublicKeyB64: vector.cases[0].serverPublicKeyB64, exp: vector.cases[0].exp })})+ // The vector pins the mirror's issue() and the client's proof; this pins the mirror's verify() to+ // the same bytes directly, instead of only through random keys. One server per case: the cases+ // share one nonce, and verify() consumes it.+ for (const c of vector.cases) {+ it(`the test server verifies the vector proof (${c.purpose}, "${c.subject}")`, () => {+ const s = createTestPopServer(vector.popSecret, { now: () => (c.exp - 60) * 1000, nonce: Buffer.from(vector.nonce, 'base64url') })+ expect(s.verify({ hostPublicKeyB64: vector.hostPublicKeyB64, purpose: c.purpose as PopPurpose, subject: c.subject, popChallenge: c.challenge, popProof: c.proof })).toBe(true)+ })+ }})describe('computePopProof', () => {@@ -34,6 +43,21 @@ describe('computePopProof', () => {const proof = popProverFor(k)({ challenge: ch.challenge, serverPublicKeyB64: ch.serverPublicKeyB64, purpose: 'host-token', subject: 'd' })expect(s.verify({ hostPublicKeyB64: pub, purpose: 'host-token', subject: 'd', popChallenge: ch.challenge, popProof: proof })).toBe(true)})+ it.each<[string, (k: nacl.BoxKeyPair, other: nacl.BoxKeyPair) => void]>([+ ['has its bytes overwritten in place', (k, other) => k.secretKey.set(other.secretKey)],+ ['is replaced by another array', (k, other) => { k.secretKey = other.secretKey }]+ ])('popProverFor captures the secret at creation: a key pair whose secret %s still proves for the public key it was made with', (_label, mutate) => {+ // The public key is captured eagerly; a secret read at call time could pair a NEW secret with the+ // OLD public key, which proves nothing the backend accepts.+ const k = nacl.box.keyPair()+ const pub = Buffer.from(k.publicKey).toString('base64')+ const prove = popProverFor(k)+ mutate(k, nacl.box.keyPair())+ const s = createTestPopServer()+ const ch = s.issue(pub, 'push')+ const proof = prove({ challenge: ch.challenge, serverPublicKeyB64: ch.serverPublicKeyB64, purpose: 'push', subject: 'x' })+ expect(s.verify({ hostPublicKeyB64: pub, purpose: 'push', subject: 'x', popChallenge: ch.challenge, popProof: proof })).toBe(true)+ })})// The fakes in later tests are only as strict as this mirror: each refusal below is one the backenddiff --git a/src/core/relay/relay-pop.ts b/src/core/relay/relay-pop.tsindex 87d0a6139..0eccf096f 100644--- a/src/core/relay/relay-pop.ts+++ b/src/core/relay/relay-pop.ts@@ -43,10 +43,13 @@ export function computePopProof(i: {export type PopProver = (i: { challenge: string; serverPublicKeyB64: string; purpose: PopPurpose; subject: string }) => string-/** A prover closed over a key pair, so callers that only need to PROVE never hold the secret. */+/** A prover closed over a key pair, so callers that only need to PROVE never hold the secret. Both+ * halves are captured at creation (the secret as a COPY), so a later mutation of the key pair object+ * — its secret's bytes or the property itself — can never pair a new secret with the old public key. */export function popProverFor(keys: { publicKey: Uint8Array; secretKey: Uint8Array }): PopProver {const hostPublicKeyB64 = Buffer.from(keys.publicKey).toString('base64')- return (i) => computePopProof({ ...i, hostSecretKey: keys.secretKey, hostPublicKeyB64 })+ const hostSecretKey = Uint8Array.from(keys.secretKey)+ return (i) => computePopProof({ ...i, hostSecretKey, hostPublicKeyB64 })}export type ChallengeResult =