Guest socket: only the platform's own fact blocks or unblocks #14
merged block-watch-source was squashed into main as d1d06c4 by jonas, 2026-11-26 20:38 UTC. jonas opened it 2026-11-26 20:37 UTC.
/agents/reviewer, 26 Nov 2026 20:35 UTC, on the block watch of pull 4 (ac30cfa): it "trusts block and unblock event types without verifying who issued them". A member's script, or loaded code, could append `account/person-blocked` on a guest's context (`/users/<id>`) and so refuse or end that guest's socket in any call; an `account/person-unblocked` written the same way could hide an owner's block from a socket that was still open. Shown on iterate.com at 20:16 UTC: a fact that a member's script wrote ended a test guest's socket after 52 s. Now the watch counts a fact of these types only when it carries `source.platform: true`. The mind Worker stamps that on what the auth Worker's answer carries (core/mind-worker/src/rpc.ts `append`), and no other caller can (core/itx/src/caller.ts builds the source from the caller). On iterate.com the auth Worker's `account/guest-signed-in` carries the stamp, and the member's fact carries `onBehalfOf` and no stamp. The auth Worker's block, its tokens and its sign-in are not changed. Tests: core/itx 540 pass (two new: a forged block ends and refuses nothing and an owner's block still ends the socket; a forged unblock hides no block). All nine packages type-check. Session: claude 54816317-8638-4f04-a7ff-dd2e968c9348 on beelink 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Conversation
Nobody has said anything yet.
Sign in to comment or to merge.
Files
2 files changed
M core/itx/src/person-context.test.ts
@@ -904,8 +904,16 @@ }); // The block, and its end, are on the guest's own context, written by the auth Worker. -const BLOCKED = { type: "events.iterate.com/account/person-blocked" }; -const UNBLOCKED = { type: "events.iterate.com/account/person-unblocked" }; +// The platform's stamp is on them: the mind Worker appends what the auth Worker's answer carries. +const BLOCKED = { type: "events.iterate.com/account/person-blocked", source: { platform: true } }; +const UNBLOCKED = { + type: "events.iterate.com/account/person-unblocked", + source: { platform: true }, +}; +/** The same types as a member's script appends them: stamped with the member, never `platform`. */ +const BY_A_MEMBER = { onBehalfOf: { principal: { actor: "user_member" } } }; +const FORGED_BLOCK = { type: BLOCKED.type, source: BY_A_MEMBER }; +const FORGED_UNBLOCK = { type: UNBLOCKED.type, source: BY_A_MEMBER }; /** A watch over a log that the test writes, with its clock and the offsets it read from. */ function blockWatch(log: unknown[]) { const world = { clock: 1_795_700_000_000, reads: [] as number[], fails: false }; @@ -949,6 +957,36 @@ expect(await blockWatch([BLOCKED]).watch.blockedNow()).toBe(true); expect(await blockWatch([BLOCKED, UNBLOCKED, BLOCKED]).watch.blockedNow()).toBe(true); expect(await blockWatch([]).watch.blockedNow()).toBe(false); +}); + +test("a block that the platform did not write ends no socket and refuses none", async () => { + // at the open: a member's script wrote the type on the guest's context, also with no source + const log: unknown[] = [FORGED_BLOCK, { type: BLOCKED.type }, { type: BLOCKED.type, source: {} }]; + const { world, watch } = blockWatch(log); + expect(await watch.blockedNow()).toBe(false); + // and during the call: the read sees it and the session goes on + log.push(FORGED_BLOCK, { type: BLOCKED.type, source: { platform: "true" } }); + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBeUndefined(); + expect(world.reads).toEqual([0, 3]); + // an owner's real block still ends it + log.push(BLOCKED); + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBe("your access to this context ended"); +}); + +test("an unblock that the platform did not write hides no block", async () => { + // at the open: an owner's block, then a member's script wrote its end + expect(await blockWatch([BLOCKED, FORGED_UNBLOCK]).watch.blockedNow()).toBe(true); + // during the call: the block and the forged end arrive in one read, and the session ends + const log: unknown[] = []; + const { world, watch } = blockWatch(log); + expect(await watch.blockedNow()).toBe(false); + log.push(BLOCKED, FORGED_UNBLOCK, { type: UNBLOCKED.type }); + world.clock += BLOCK_EVERY_MS; + expect(await watch.onFrame()).toBe("your access to this context ended"); + // an owner's real end of the block counts, as before + expect(await blockWatch([BLOCKED, FORGED_UNBLOCK, UNBLOCKED]).watch.blockedNow()).toBe(false); }); test("reads of the guest's log that fail: one says nothing, three in a row end the session", async () => {
M core/itx/src/person-context.ts
@@ -563,7 +563,10 @@ * socket that outlives the sign-in asks for no token again. The auth Worker writes a block, and * its end, on the guest's own context (`/users/<id>`, core/auth-worker/src/members.ts), and * `read` reads that log from an offset on. Whether the guest is blocked is what the log says - * last: no clock is compared. + * last: no clock is compared. ONLY THE PLATFORM'S OWN FACT COUNTS (`source.platform`, which the + * mind Worker stamps on what the auth Worker's answer carries and on nothing else): anyone who + * can append to the mind can write an event of these types on that context, and such an event + * neither ends a guest's socket nor hides an owner's block from it. * - `blockedNow` reads the log at the open: a guest who is blocked gets no socket, also when the * upgrade was stamped a moment before the block. * - `onFrame` reads on the socket's traffic, at most every `BLOCK_EVERY_MS`. A socket has a frame @@ -581,7 +584,14 @@ }) { const now = args.now || Date.now; const Page = z.object({ - events: z.array(z.object({ type: z.string() }).loose()), + events: z.array( + z + .object({ + type: z.string(), + source: z.object({ platform: z.unknown().optional() }).loose().optional(), + }) + .loose(), + ), scannedThroughOffset: z.number(), atHead: z.boolean(), }); @@ -597,6 +607,9 @@ const page = Page.safeParse(await args.read(after).catch(() => null)); if (!page.success) return void (failures += 1); for (const event of page.data.events) { + // the platform's own append alone (core/itx/src/caller.ts stamps it, and nobody else + // can): a fact of these types that a member or loaded code wrote says nothing here + if (event.source?.platform !== true) continue; if (event.type === PERSON_BLOCKED) blocked = true; else if (event.type === PERSON_UNBLOCKED) blocked = false; }