Guest socket: only the platform's own fact blocks or unblocks
Jonas Templestein, 2026-11-26 20:37 UTC · 160a2c75a4e4d5d826a530fc0987562c1c199a29 · parent a653591
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; }