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
docs: relay key intake, SAS v2 and the QR sshHostKeys contract
review8b020626a512
diff --git a/CLAUDE.md b/CLAUDE.mdindex 87d438f59..03561b029 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -9494,6 +9494,45 @@ unix-socket forward and dev-server `-L` forward over it. POSIX keeps OpenSSH unt## Remote access (phone relay) — free, not Pro+- **Relay key intake: no low-order keys, one spelling per key, a 10-digit SAS** (security audit+ 2026-10, relay-crypto F1–F5). (1) `deriveSharedKey` (`core/relay/e2ee.ts`) refuses a peer key whose+ RAW X25519 output is all zero (`WeakPeerKeyError`, `E_WEAK_PEER_KEY`): tweetnacl's `box.before`+ accepts low-order points, and with one the shared key is HSalsa20(0), a public constant — a+ secret-less client completed the handshake, both humans saw the same fixed SAS ("357 836"), and a+ 0^32 key pinned through a tampered offer/join code let anyone back in silently (`autoApprove`).+ Check the raw X25519 output, never `box.before`'s. The host refuses in the `e2ee_hello` handler+ WITHOUT answering and closes the socket (no throw inside the ws emit), and sets `peerPubB64` only+ after a successful derive, so nothing can pin or auto-approve the refused key; a client throws in+ `connectRelay` before dialing. The intakes are belts on that choke point: `decodeOffer`,+ `decodeJoinCode`, `ownerKeyProblem`, `pinDevice`/`isPinned`, and the `/pair` `epk` (400 `bad+ epk`) — `isLowOrderPublicKey` uses a fixed probe scalar, since any clamped scalar sends exactly+ the low-order points to zero. Pinned by `relay-low-order.test.ts` (the audit's repro, against the+ real host and client). (2) Keys and nonces must be CANONICAL padded base64 (`canonicalB64ToBytes`):+ Node's decoder skips junk, so `"!!!" + key` decoded to the key, and pin stores compare strings.+ A join code's body is canonical base64url too, after removing ASCII whitespace (wrapped mail+ lines). Every producer (desktop, iOS, Android, web viewer) pads already. (3) The SAS is v2:+ `pad6(BE_u32(h[0..4]) mod 1e6) + pad4(BE_u32(h[4..8]) mod 1e4)`, "NNN NNN NNNN", h =+ SHA-512(shared). v1 (~20 bits) was grindable on both legs in seconds by whoever substitutes a+ pinned key. The first seven characters are the v1 code, and every surface shows+ `SAS_COMPARE_HINT` (`shared/remote/sas.ts`) under the code — the host approval dialog+ (`shared/remote/approval.ts`), the joiner's prompt (Canvas), the hosted owner dialog and `team+ status`. Nothing compares SAS strings in code, so mixed versions stay correct; vectors in+ `e2ee.test.ts` and docs/ios-protocol-migration.md §3.1 (the phones owe their own release). (4) The+ host SAS dialog has one slot: a DIFFERENT device's pending request is refused while one is open+ (`renderer/lib/pendingPeerAdmission.ts`: a phone is rejected and retries, a relay peer is never+ confirmed), never swapped in under the human comparing digits; the same device re-raising (#372+ retry churn) replaces in place. (5) The pairing QR carries `sshHostKeys` (`SHA256:…` `ssh-keygen+ -lf` spelling, ordered ed25519/ecdsa/rsa, at most 4, after `relay`, before `ssh`; always omitted+ with `ssh:false`), so the phone pins its first SSH connect instead of TOFU+ (`main/ssh-host-key-fingerprint.ts`; phones: nodeterm-ios#75 + Android). **COMPLETE OR ABSENT,+ never partial**: the phones REFUSE a host key not in the set, and sshd presents whichever key the+ client's algorithm preference picks, so a missing key locks the phone out until a new QR. The set+ is what sshd would serve: `HostKey` lines of sshd_config + its `Include`s (else sshd's defaults),+ each counted only if its private file exists (stat, never read), each `.pub` required to parse.+ Any doubt drops the field — an unreadable `.pub`, `HostKeyAgent`, a relative or `%`/`~` path, a+ glob form we do not model, more than 4 keys; an unreadable config falls back to the defaults+ only when all three are present and consistent. A superset is harmless.+- **A Team Access invite that shares ONE project is a boundary, not a label**(`core/relay/scoped-guest-policy.ts`, wired by `main/remote/relay-host.ts` as the core relayhost's hooks). The invite is consent to run commands IN that project, and nothing else: inbound isdiff --git a/CONTRIBUTING.md b/CONTRIBUTING.mdindex a7c234025..87e83e7e5 100644--- a/CONTRIBUTING.md+++ b/CONTRIBUTING.md@@ -744,6 +744,15 @@ anything else. Board-level fields survive every transform — `pullLinks` is onenot fold one into the other. Change the relay protocol and `relay-pop-vector.json` must change inboth repos. Deep version: CLAUDE.md § Hosted team relay.+- **A peer's X25519 key goes through `src/core/relay/e2ee.ts`, never straight into+ `nacl.box.before`.** `deriveSharedKey` refuses a low-order key (raw X25519 output all zero: the+ shared secret would be a public constant, the SAS a fixed value) and `publicKeyFromB64` refuses+ non-canonical base64; a new intake of a key someone will PIN (an offer, a code, a QR field, a pin+ store) validates with `peerPublicKeyFromB64` / `isUsablePeerKeyB64` and gets a+ `low-order-keys.test-support.ts` test. A new surface that SHOWS the SAS shows `SAS_COMPARE_HINT`+ (`src/shared/remote/sas.ts`) under it, and nothing compares SAS strings across builds (a v1 peer+ shows the first six of the ten digits). Deep version: CLAUDE.md § Remote access.+- **Normalize BOTH sides of a path comparison, through one function.** A marker normalized whereit is built and matched raw where it is used is a no-op on the machine you wrote it on and asilent defect on Windows. That is issue #558: the managed-hook marker was folded to `/` whilediff --git a/docs/hosted-team-relay.md b/docs/hosted-team-relay.mdindex c8edf8c03..cb28e61aa 100644--- a/docs/hosted-team-relay.md+++ b/docs/hosted-team-relay.md@@ -394,7 +394,7 @@ and host key already exists, sets `approvedAt` on it and keeps its device tokenThat is safe only because of what `seedBookmark` is given: the join code `team bootstrap` justreturned over the project's own SSH channel, whose host key `known_hosts` already authenticated. Thecode names the relay key it was minted for (`decodeJoinCode` checks that the host id is the hash of-that key), which is the assurance comparing six digits by eye gives. Main enforces that input: it+that key), which is the assurance comparing the SAS digits by eye gives. Main enforces that input: itseeds only a code a successful `team bootstrap` returned during this app run (kept per project, inmemory), and refuses any other code, however valid, so that join compares the SAS. The host approvesits own half because your key is an owner in `team.json`. If the seed fails, the join asks for thediff --git a/docs/ios-protocol-migration.md b/docs/ios-protocol-migration.mdindex 96ef502fb..3be72075a 100644--- a/docs/ios-protocol-migration.md+++ b/docs/ios-protocol-migration.md@@ -309,21 +309,60 @@ Stage 4 makes the phone a **peer**, and a pairing **grants shell access** on themachine. The only thing between a relay MITM and that shell is **mutual SAS approval**:BOTH humans compare the same 6-digit code out of band, and BOTH press Confirm.-### 3.1 The SAS (6 digits) — `sasFromSharedKey` (e2ee.ts 89–95)+### 3.1 The SAS (v2: 10 digits) — `sasFromSharedKey` (e2ee.ts)-Both ends derive the identical code from `baseKey` (the ECDH shared secret — **not**-the session key):+Both ends derive the identical code from `baseKey` (the ECDH shared secret, i.e. NaCl+`box.before` = HSalsa20(X25519) — **not** the session key):```-h = SHA-512(baseKey) // nacl.hash-n = ((h[0]<<24) | (h[1]<<16) | (h[2]<<8) | h[3]) >>> 0 // first 4 bytes, BIG-endian, unsigned 32-bit-code = (n % 1_000_000) padded to 6 digits-SAS = "NNN NNN" // a space between the two triples+h = SHA-512(baseKey) // nacl.hash+a = BE_u32(h[0..4]) mod 1_000_000 // the v1 code+b = BE_u32(h[4..8]) mod 10_000 // four more digits+SAS = pad6(a)[0..3] + " " + pad6(a)[3..6] + " " + pad4(b) // e.g. "123 456 7890"```-iOS must compute exactly this and **display it**, so the human can compare it with the-digits shown on the desktop. A MITM terminating two different ECDH exchanges yields two-different codes → the humans refuse.+`BE_u32(x)` = the four bytes read **big-endian, unsigned**. The first seven characters are+exactly the v1 code (`"NNN NNN"`, ~20 bits), so a peer on an older build that still shows six+digits can be compared on the first six. v1 alone was grindable: an attacker who substitutes a+pinned key (a tampered offer, join code or QR) matched both legs in seconds; v2 is ~33 bits.++Every surface that shows the SAS shows, under it, exactly: *"Compare all ten digits. If the+other device shows only six, it runs an older version: compare the first six."*+(`src/shared/remote/sas.ts`).++Test vectors (`src/core/relay/e2ee.test.ts`; computed independently with Python `hashlib`):++| baseKey (32 bytes) | SAS |+|---|---|+| 32 × `0x00` | `809 281 4822` |+| 32 × `0x01` (SHA-512 begins `5ce86efb 75fa4e2c`) | `736 635 8284` |+| `0x00, 0x01, …, 0x1f` | `170 596 5663` |+| 32 × `0xff` | `773 237 5799` |+| `0x00, 0x17`, then 30 × `0x00` | `071 120 4361` (leading zero in the six) |+| `0x00, 0x0b`, then 30 × `0x00` | `243 975 0790` (leading zero in the four) |++End to end: secret A = 32 × `0x01`, secret B = 32 × `0x02` → pubA+`pOCSkrZRwni5dyxWn1+puxPZBrRqtoyd+dwrRAn4ogk=`, pubB+`zo060cy2M+x7cMF4FKXHbs0CloUFDTRHRboFhw5YfVk=`, raw X25519+`2ed76ab549b1e73c031eb49c9448f0798aea81b698279a0c3dc3e49fbfc4b953`, `box.before`+`18a99320f3488fa18a04239715d8ee738065e65c3d4b2898522d6c3d4ead588c`, SAS **`561 048 8895`**.++A MITM terminating two different ECDH exchanges yields two different codes → the humans refuse.++### 3.1a Key intake: low-order keys and canonical base64++- **Refuse a low-order peer key.** If the raw `X25519(ourSecret, theirPub)` is all zero, the+ key is a small-order point (0, 1, the two order-8 points, p−1, p, p+1, each also with the top+ bit set) and `box.before` would be HSalsa20(0): a **public constant**. A secret-less peer then+ completes the handshake, both humans see the same fixed SAS, and anyone on the wire derives the+ session key. The desktop refuses such a key everywhere it takes one (handshake both roles,+ pairing offer, join code, `/pair` `epk`, pin stores, `team add-owner`) and closes the socket+ without answering. A phone must refuse it too — above all the **host key it pins** (QR+ `hostKey`, relay block, `relay.json`): check the raw X25519 output, not the `box.before` output.+- **Canonical base64 only**, padded, standard alphabet: the decoded bytes must re-encode to the+ exact input. Node's decoder skips junk (`"!!!" + key` decodes to the key), and keys are compared+ as strings in every pin store, so a second spelling is both a disguise and a key that matches+ none of its own pins. Every producer pads already.### 3.2 The confirm frame — MUST ride the ENCRYPTED tunnel@@ -568,9 +607,11 @@ alone leaves the phone unable to connect. File and land them together.## 7. Security requirements iOS MUST honour (checklist)-1. **Compare the SAS out of band.** Compute `sasFromSharedKey(baseKey)` exactly (§3.1),- display "NNN NNN", and require the human to confirm it matches the desktop before- proceeding. This is the only defence against a relay MITM.+1. **Compare the SAS out of band.** Compute `sasFromSharedKey(baseKey)` exactly (§3.1, v2),+ display "NNN NNN NNNN" with the compare-all-ten copy, and require the human to confirm it+ matches the desktop before proceeding. This is the only defence against a relay MITM.+1a. **Refuse a low-order peer key and non-canonical base64** (§3.1a), at every place a key is+ taken — above all the host key you pin.2. **Send the confirm ONLY over the encrypted tunnel** as `{t:'cast',method:'trust:confirm', args:[]}` via a TAG_TUNNEL_TEXT box. Never send a plaintextconfirm — the desktop rejects it and it is a security hole.@@ -588,8 +629,36 @@ alone leaves the phone unable to connect. File and land them together.7. **Persist your own box keypair** (keychain). A fresh ephemeral key each launch wouldforce re-approval every time and break pinning.8. **Endianness discipline:** box seq is little-endian (2×uint32 LE, high then low);- `encodePtyData` sidLen is big-endian uint16; SAS folds `h[0..4]` big-endian. Do not- cross them.+ `encodePtyData` sidLen is big-endian uint16; SAS folds `h[0..4]` and `h[4..8]` big-endian.+ Do not cross them.+10. **Pin the SSH host key from the pairing QR** (§7.1) instead of trusting the first connect.++### 7.1 The pairing QR's `sshHostKeys` (desktop `pairing-core.ts` `buildPairingPayload`)++The QR now carries this host's SSH host-key fingerprints, so the phone's first SSH connect after+pairing is no longer trust-on-first-use (an on-path attacker could otherwise serve a forged+`agent.json` / `relay.json` over that first connection):++- key `sshHostKeys`: JSON array of OpenSSH SHA-256 fingerprints,+ `"SHA256:<standard base64 of sha256(keyBlob), trailing '=' removed>"` — the `ssh-keygen -lf`+ spelling; `keyBlob` = base64-decode of the `.pub` line's second field (the SSH wire blob, the same+ bytes the server presents). At most 4, ordered ed25519, ecdsa, rsa.+- position: after `relay` (or after `hostKey` / `name` when those are absent), before `ssh`.+- **complete or absent, never partial.** The phone refuses a key not in the set, and sshd presents+ whichever of its keys the client's algorithm preference picks, so a partial list would lock the+ phone out. The desktop lists exactly what sshd would serve: the `HostKey` paths of+ `/etc/ssh/sshd_config` and the files it `Include`s (else sshd's defaults+ `/etc/ssh/ssh_host_{rsa,ecdsa,ed25519}_key`), each counted only when its private file exists, and+ each `.pub` must read and parse (a blob naming a different algorithm than its first field is+ refused). Any doubt omits the field: an unreadable `.pub`, `HostKeyAgent`, a relative or+ tokenized path, an `Include` glob form it does not model, more than 4 keys. With the config+ unreadable, the defaults are used only when all three are present and consistent.+- omitted when there is no complete list, and **always** omitted with `ssh:false` (Windows) — that+ payload is byte-identical to before.++Phone side (iOS / Android follow-up): when present, accept the first SSH connect only if the+server's key fingerprint is in the list, and pin it at commit instead of `forget`ting the pin;+absent = the old TOFU behaviour.9. **`undef` correctness** (§1.2) on both encode and decode, so a meaningful `null`(park, presence-clear) is never mistaken for an omitted argument.diff --git a/docs/remote-sessions.md b/docs/remote-sessions.mdindex e2c4c658f..b6516e61c 100644--- a/docs/remote-sessions.md+++ b/docs/remote-sessions.md@@ -192,7 +192,7 @@ tab).### Trust (4d — scoped to the crypto/pairing layer)- The peer's device key becomes **persistent** (today the client key is ephemeral)- and is **pinned on both ends**; SAS (6-digit) is verified **mutually**.+ and is **pinned on both ends**; SAS (10-digit v2; a v1 peer shows the first six) is verified **mutually**.- Revocation is a first-class action (facepile avatar → "Remove"): it unpins the key**and kills the live session** — closes the relay connection, drops the peer's ptysubscriptions, leaves presence. Unpinning alone would leave the peer connected.@@ -237,7 +237,7 @@ function confirmLocal(s: MutualApproval): MutualApprovalfunction confirmRemote(s: MutualApproval): MutualApprovalfunction isMutuallyApproved(s: MutualApproval): booleanfunction recordApproval(store: ApprovedDevices, s: MutualApproval): ApprovedDevices // pins s.peerKeyB64 only when both confirmed-function mutualSas(shared: Uint8Array): string // "NNN NNN"; alias of sasFromSharedKey+function mutualSas(shared: Uint8Array): string // "NNN NNN NNNN"; alias of sasFromSharedKey```Flow: `emptyMutualApproval(peerKeyB64, sessionId)` → `confirmLocal` on this human's SAS@@ -586,7 +586,7 @@ session):`/tmp/nt-B`). Then:1. On A, start a remote host (New Remote Connection → host), **pick which project to share**(default = active), and copy the pairing offer.- 2. On B, paste the offer → both show the **same 6-digit SAS** → B sees the **ConsentNotice**+ 2. On B, paste the offer → both show the **same 10-digit SAS** → B sees the **ConsentNotice**on A's approval → confirm on both → the **shared project opens as a tab on B, alreadypopulated with A's nodes** (NOT a blank canvas — this is the project-scope check). B sees ONLYthe shared project, not A's other projects.