Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(access): a remote-owned job reads as its client's live member (GBRA-218)
garrytan26d44eb23b51
diff --git a/src/core/minions/tools/brain-allowlist.ts b/src/core/minions/tools/brain-allowlist.tsindex c68b85c850..a5e6e5393f 100644--- a/src/core/minions/tools/brain-allowlist.ts+++ b/src/core/minions/tools/brain-allowlist.ts@@ -34,6 +34,8 @@ import type { ToolCtx, ToolDef } from '../types.ts';import { putPageRejection, rethrowWithCurrentRevision } from './put-page-result.ts';import { BRAIN_TOOL_ALLOWLIST } from './brain-tool-allowlist.ts';import { stagePutPage } from './staged-put-page.ts';+import { withCallerAccess } from '../../search/private-visibility.ts';+import { remoteCallerAccess } from '../../access/caller.ts';// The allow-list itself lives in a handler-free module so the MCP surface// tiers (src/mcp/surface.ts) can read it without this module's operations import.@@ -304,9 +306,14 @@ function brainTool(op: Operation, opts: BuildBrainToolsOpts): ToolDef {const validationError = validateParams(op, params);if (validationError) throw new Error(`${toolName}: ${validationError}`);const write = op.name === 'put_page' && opts.stageWrites ? stagePutPage : op.handler;- const output = op.name === 'put_page'- ? await write(opCtx, params).catch(e => rethrowWithCurrentRevision(ctx.engine, opCtx.sourceId ?? 'default', params.slug, e))- : await op.handler(opCtx, params);+ const run = () => op.name === 'put_page'+ ? write(opCtx, params).catch(e => rethrowWithCurrentRevision(ctx.engine, opCtx.sourceId ?? 'default', params.slug, e))+ : op.handler(opCtx, params);+ // GBRA-218: a remote-owned job reads as its client's member, looked up live on every call (a disabled member or+ // removed binding takes effect at the next tool call); never a GBRA-156 private-pages grant.+ const output = opCtx.auth+ ? await withCallerAccess(await remoteCallerAccess(ctx.engine, opCtx.auth, []), run)+ : await run();const rejection = op.name === 'put_page' ? putPageRejection(output) : null;if (rejection) throw new Error(rejection);if (op.name === 'get_page' && opts.readBudgetBytes) return budgetedPageRead(ctx.engine, ctx.jobId, opts.readBudgetBytes, params.slug, output);diff --git a/test/minions/delegated-execution.serial.test.ts b/test/minions/delegated-execution.serial.test.tsindex 356200b4b2..6f63f85f83 100644--- a/test/minions/delegated-execution.serial.test.ts+++ b/test/minions/delegated-execution.serial.test.ts@@ -145,6 +145,22 @@ describe('remote-owned production tool visibility', () => {}}, 30_000);+ it('GBRA-218: a job reads as its client\'s bound member, re-resolved on every tool call', async () => {+ const ctx = await ownedJob();+ await engine.executeRaw("INSERT INTO access_members (id) VALUES ('alice-example')");+ await importFromContent(engine, 'notes/member-job', '---\ntitle: Member job\ntype: note\nreadable_by: [alice-example]\n---\nCanary jobmemberread.', { noEmbed: true, sourceId: 'default' });+ const read = productionTools(ctx).find(tool => tool.name === 'brain_get_page')!;+ const sees = async () => JSON.stringify(await read.execute({ slug: 'notes/member-job', include_content: true }, { engine, jobId: ctx.id, remote: true }).catch(e => String(e))).includes('jobmemberread');+ expect(await sees()).toBe(false);+ await engine.executeRaw("UPDATE oauth_clients SET member_id = 'alice-example' WHERE client_id = 'owner'");+ expect(await sees()).toBe(true);+ await engine.executeRaw("UPDATE access_members SET disabled_at = now() WHERE id = 'alice-example'");+ expect(await sees()).toBe(false);+ await engine.executeRaw("UPDATE access_members SET disabled_at = NULL WHERE id = 'alice-example'");+ await engine.executeRaw("UPDATE oauth_clients SET member_id = NULL WHERE client_id = 'owner'");+ expect(await sees()).toBe(false);+ });+it('every source-selecting read enforces the current grant including explicit overrides', async () => {const ctx = await ownedJob(null, {}, ['get_page', 'search', 'query', 'list_pages', 'resolve_slugs']);await engine.executeRaw("INSERT INTO sources(id,name) VALUES ('other','Other fixture')");