Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
fix(access): only the caller's own member page judges its facts as the caller; other memory/members pages keep master's empty-identity filter (hide-only)
garrytand2ad64c3b859
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.tsindex b411ba76b6..ae578d9442 100644--- a/src/core/search/private-visibility.ts+++ b/src/core/search/private-visibility.ts@@ -24,7 +24,7 @@ import { AsyncLocalStorage } from 'node:async_hooks';import type { BrainEngine } from '../engine.ts';import { requestConfigRows } from '../config-snapshot.ts';import { isValidSourceId } from '../source-id.ts';-import { hasReaders, MEMBER_PAGE_PREFIX, normalizePrincipal, readersAllow, validIdentity } from '../access/principals.ts';+import { ACCESS_ID_RE, hasReaders, MEMBER_PAGE_PREFIX, normalizePrincipal, readersAllow, validIdentity } from '../access/principals.ts';import { validPrefix, validQualifiedRuleId } from '../access/folder-rules.ts';export const REMOTE_PRIVATE_PAGES_KEY = 'search.remote_private_pages';@@ -624,16 +624,18 @@ export function privateTimelineEventFilterForCaller(timelineAlias: string): stri* always applies (a world fact held in or extracted from a page that names readers stays hidden from every remote* caller, as with the plain fragment); the privacy part is dropped when an operator relaxed privacy for this remote* read, which is what the hatches did to these reads before member access (`excludePrivate` was false then).- * Outside a remote record nothing relaxes it. GST-359 C2: a fact on a member page (`memory/members/<member>`) alone- * is judged as the caller (its member identity, or every audience entry), so its member reads it back.+ * Outside a remote record nothing relaxes it. GST-359 C2: a fact on the caller's own member page+ * (`memory/members/<member>`, one attested or bound member) alone is judged as the caller, so its member reads it back;+ * every other page, other members' pages included, keeps the empty identity.*/export function privateProvenanceFilterUnderPolicy(factAlias: string): string {const access = currentCallerAccess();- const identity = access.audienceIdentities.length ? { all: access.audienceIdentities } : access.identity;const hide = !callerRelaxesPrivacy();- const memberPage = `starts_with(pp.slug, '${MEMBER_PAGE_PREFIX}')`;- return `NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id AND pp.slug = ${factAlias}.source_markdown_slug ` +- `AND NOT CASE WHEN ${memberPage} THEN ${readPolicyFragment('pp', identity, hide, access.satisfiedRuleIds)} ELSE ${readPolicyFragment('pp', [], hide)} END)`;+ const member = access.actor?.member ?? (access.audienceIdentities.length ? null : access.identity.find(p => p.startsWith('member:'))?.slice('member:'.length));+ const policy = member && ACCESS_ID_RE.test(member)+ ? `CASE WHEN pp.slug = '${MEMBER_PAGE_PREFIX}${member}' THEN ${readPolicyFragment('pp', access.identity, hide, access.satisfiedRuleIds)} ELSE ${readPolicyFragment('pp', [], hide)} END`+ : readPolicyFragment('pp', [], hide);+ return `NOT EXISTS (SELECT 1 FROM pages pp WHERE pp.source_id = ${factAlias}.source_id AND pp.slug = ${factAlias}.source_markdown_slug AND NOT (${policy}))`;}/** True only inside a remote caller record whose read an operator relaxed (the env hatch or the config opt-out). */diff --git a/test/access-member-facts.test.ts b/test/access-member-facts.test.tsindex ebe587f384..6a051ae145 100644--- a/test/access-member-facts.test.ts+++ b/test/access-member-facts.test.ts@@ -217,6 +217,18 @@ for (const kind of testBackends()) {__resetPrivateVisibilityCacheForTests();}, 60_000);+ test('a world fact on another member page stays hidden from a caller its readers name, as on master', async () => {+ const page = 'memory/members/quinn-example';+ await importFromContent(engine, page, '---\ntype: note\ntitle: Quinn notes\nreadable_by:\n - member:bob-example\n---\n# Quinn notes\n', { sourceId: SRC });+ await engine.insertFact({ fact: 'canaryhandwrittenmember harbor ledger', kind: 'fact', entity_slug: ACME, source: 'test', visibility: 'world' }, { source_id: SRC });+ await engine.executeRaw('UPDATE facts SET source_markdown_slug = $1 WHERE fact LIKE $2', [page, 'canaryhandwrittenmember%']);+ __resetPrivateVisibilityCacheForTests();+ __resetHotMemoryCacheForTests();+ for (const params of [{ query: 'harbor ledger' }, { entity: ACME }, { since: '2000-01-01' }]) {+ expect((await call(who.bobToken(), 'recall', params)).all).not.toContain('canaryhandwrittenmember');+ }+ }, 60_000);+test('a member stops reading its own facts once its page\'s readers no longer name it', async () => {const bobPage = 'memory/members/bob-example';await engine.executeRaw(`UPDATE pages SET frontmatter = jsonb_set(frontmatter, '{readable_by}', '["group:team-a"]'::jsonb) WHERE source_id = $1 AND slug = $2`, [SRC, bobPage]);