Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix: only the backend may send machine_meta

Kelvin6549e05d2dce
diff --git a/cli/src/backendSocket.spec.ts b/cli/src/backendSocket.spec.ts
index 87936f4ae..eb6e9b796 100644
--- a/cli/src/backendSocket.spec.ts
+++ b/cli/src/backendSocket.spec.ts
@@ -1701,6 +1701,32 @@ describe('machine_meta carries the grid name without clobbering it on rename', (
await socket.stop()
})
+
+ it('refuses a machine_meta that arrived over the LOCAL socket — only the backend may name the grid', async () => {
+ const socket = new BackendSocket('token')
+ const namesSeen: Array<string | null> = []
+ socket.onMachineMeta = (n) => { namesSeen.push(n) }
+ socket.connect()
+ const ws = wsMock.instances[0]
+ ws.open()
+
+ // The backend's own frame sets it, as always.
+ ws.message({ t: 'down', connId: 'web-1', frame: { type: 'machine_meta', payload: { name: 'mac', gridName: 'someone-7f3a91c4' } } })
+ await vi.waitFor(() => expect(socket.gridName()).toBe('someone-7f3a91c4'))
+
+ // Now the same frame from a process on this machine, through the local socket — the shape of the
+ // leftover script that once redirected this account's agents onto a grid of its choosing.
+ const local = 'local:1'
+ socket.registerLocalClient(local, { sendFrame: () => true, sendBinary: () => true })
+ socket.handleLocalFrame(local, { type: 'machine_meta', payload: { name: 'hijacked', gridName: 'attacker-deadbeef' } })
+
+ // Give the queue a turn: the frame must be dropped whole, so neither half of it lands.
+ await new Promise((r) => setTimeout(r, 50))
+ expect(socket.gridName()).toBe('someone-7f3a91c4')
+ expect(namesSeen).not.toContain('hijacked')
+
+ await socket.stop()
+ })
})
/** The read-only hardware line for the run-a-harness-compute dialog, answered next to `grid_models_list`. */
diff --git a/cli/src/backendSocket.ts b/cli/src/backendSocket.ts
index fa95e3a3a..4b30112b1 100644
--- a/cli/src/backendSocket.ts
+++ b/cli/src/backendSocket.ts
@@ -144,6 +144,16 @@ export function isLocalClientId(connId: string): boolean {
return connId.startsWith('local:')
}
+/**
+ * Where a down-frame came from, carried with it to `dispatchDown`.
+ *
+ * `relay` is the backend link and ONLY the backend link; `local` is a process on this machine
+ * talking to the daemon's local socket; `p2p` is a paired device over its own channel. The
+ * distinction is a trust boundary, not bookkeeping: a handful of frames are the backend's alone to
+ * send, and before `local` existed they were accepted from anything that could open the local port.
+ */
+export type DownTransport = 'relay' | 'local' | 'p2p'
+
interface QueueItem {
id: number
data: string
@@ -940,10 +950,15 @@ export class BackendSocket {
await this.terminalStreams?.closeConnection(connId, 'local client disconnected', false)
}
- /** Route an authenticated local JSON frame through the existing per-client FIFO. */
+ /** Route an authenticated local JSON frame through the existing per-client FIFO.
+ *
+ * ⚠️ Tagged `'local'`, not left to default to `'relay'`. These frames come from a process on THIS
+ * machine over the local socket, and until they were tagged they arrived at `dispatchDown`
+ * indistinguishable from the backend's own — which let any local process send a frame only the
+ * backend is entitled to send. See the `machine_meta` branch there. */
handleLocalFrame(connId: string, frame: Frame): void {
if (!this.localClients.has(connId)) return
- this.enqueueDown(frame, connId)
+ this.enqueueDown(frame, connId, 'local')
}
/** Route an authenticated local terminal frame without applying cloud E2EE. */
@@ -994,7 +1009,7 @@ export class BackendSocket {
connId: string,
type: string,
payload: Record<string, unknown>,
- transport: 'relay' | 'p2p',
+ transport: DownTransport,
): void {
if (type === 'terminal_open' && typeof payload.requestId === 'string') {
let pending = this.p2pPendingOpens.get(connId)
@@ -1016,7 +1031,7 @@ export class BackendSocket {
streams.add(streamId)
return
}
- if (transport === 'relay' && streamId) this.p2pStreams.get(connId)?.delete(streamId)
+ if (transport !== 'p2p' && streamId) this.p2pStreams.get(connId)?.delete(streamId)
}
private routeTerminalOutputToP2p(connId: string, type: string, payload: Record<string, unknown>): boolean {
@@ -1048,7 +1063,7 @@ export class BackendSocket {
console.warn(`[terminal-p2p] conn=${sid(connId)} fallback=relay reason=${reason}`)
}
- private enqueueDown(frame: Frame, connId: string, transport: 'relay' | 'p2p' = 'relay'): void {
+ private enqueueDown(frame: Frame, connId: string, transport: DownTransport = 'relay'): void {
const key = connId || '__backend__'
const previous = this.downChains.get(key) ?? Promise.resolve()
const next = previous
@@ -1169,7 +1184,7 @@ export class BackendSocket {
this.send({ type: resultType, payload: { requestId, ...payload } })
}
- private async dispatchDown(frame: Frame, connId: string, transport: 'relay' | 'p2p' = 'relay'): Promise<void> {
+ private async dispatchDown(frame: Frame, connId: string, transport: DownTransport = 'relay'): Promise<void> {
const type = frame.type as string | undefined
if (!type) return
const local = this.localClients.has(connId)
@@ -1259,6 +1274,16 @@ export class BackendSocket {
// Machine display name (seed on connect + web renames) — mirrored locally for `harness status`.
if (type === 'machine_meta') {
+ // ⚠️ The BACKEND's frame and nobody else's. It carries this machine's display name and, more
+ // to the point, the account's private grid — the grid every agent on this computer is then
+ // pointed at. Accepted from any transport, it let a process that could open the daemon's local
+ // port redirect the account's inference somewhere of its choosing, and a leftover test script
+ // doing exactly that by accident cost hours to find. No client sends this frame; there is
+ // nothing to be compatible with.
+ if (transport !== 'relay') {
+ console.warn(`[backend] ignoring machine_meta from ${transport} (${connId}) — only the backend may send it`)
+ return
+ }
// A malformed/hostile frame's payload need not be an object; `'gridName' in meta` would throw
// on a primitive (and drop the whole frame via enqueueDown's catch). Guard the type first, the
// way the plain property reads elsewhere in this dispatcher tolerate one.