Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(access): a member fact is admitted only while its member page passes the caller's full page filter (privacy included); inventory count for access_member_links (GST-359 train C)

garrytana37c25e7c540
diff --git a/src/core/access/member-facts.ts b/src/core/access/member-facts.ts
index faea6755fb..3e1c62a5bd 100644
--- a/src/core/access/member-facts.ts
+++ b/src/core/access/member-facts.ts
@@ -12,7 +12,7 @@
*/
import { createHash } from 'node:crypto';
import type { OperationContext } from '../ops/contract.ts';
-import { callerAccessAllowedSql, currentCallerAccess, folderRestrictedSql } from '../search/private-visibility.ts';
+import { currentCallerAccess, folderRestrictedSql, privatePagesFilterForCaller } from '../search/private-visibility.ts';
import { ACCESS_ID_RE, MEMBER_PAGE_PREFIX, normalizeReaders } from './principals.ts';
import { opError, type OperationError } from '../ops/contract.ts';
import { slugifyPath } from '../sync.ts';
@@ -74,8 +74,8 @@ export function memberPageFrontmatter(member: string): string {
}
/**
- * The private facts the current caller may read: those on its own member page, while that live page's readers (and
- * folder rules) admit the caller. FALSE outside a member caller record. `alias` is a code-provided facts alias; the
+ * The private facts the current caller may read: those on its own member page, while the caller may read that live
+ * page itself (its readers, folder rules and privacy, as get_page judges it). FALSE outside a member caller record. `alias` is a code-provided facts alias; the
* member id passed ACCESS_ID_RE, whose alphabet has no quote.
*/
export function memberFactAdmitSql(alias: string): string {
@@ -84,7 +84,7 @@ export function memberFactAdmitSql(alias: string): string {
return `(${alias}.visibility = 'private' AND ${alias}.source_markdown_slug = '${memberPageSlug(member)}' AND EXISTS (
SELECT 1 FROM pages member_page WHERE member_page.source_id = ${alias}.source_id AND member_page.slug = ${alias}.source_markdown_slug
AND member_page.deleted_at IS NULL AND member_page.page_readers && ARRAY['member:${member}']::text[]
- AND ${callerAccessAllowedSql('member_page')}))`;
+ AND ${privatePagesFilterForCaller('member_page')}))`;
}
/** A remote fact read's visibility list as SQL: the listed values, widened only by memberFactAdmitSql. */
diff --git a/test/access-member-facts.test.ts b/test/access-member-facts.test.ts
index 1f601796d1..8d010245c6 100644
--- a/test/access-member-facts.test.ts
+++ b/test/access-member-facts.test.ts
@@ -151,6 +151,40 @@ for (const kind of testBackends()) {
}
}, 60_000);
+ test('a member fact is read only while its member page itself is readable: a page an operator marked private hides its facts too', async () => {
+ const page = 'memory/members/alice-example';
+ expect((await call(who.alice(), 'recall', { query: 'harbor' })).all).toContain(CANARY.alice);
+ for (const marker of [{ visibility: 'private' }, { derived_from: 'notes/private-origin-example' }]) {
+ if ('derived_from' in marker) await importFromContent(engine, 'notes/private-origin-example', '---\ntype: note\nvisibility: private\n---\n# Private origin\n', { sourceId: SRC });
+ await engine.executeRaw('UPDATE pages SET frontmatter = frontmatter || $3::jsonb WHERE source_id = $1 AND slug = $2', [SRC, page, JSON.stringify(marker)]);
+ try {
+ __resetPrivateVisibilityCacheForTests();
+ __resetHotMemoryCacheForTests();
+ expect((await call(who.alice(), 'get_page', { slug: page })).all).not.toContain(CANARY.alice);
+ for (const params of [{ query: 'harbor' }, { entity: ACME }, { since: '2000-01-01' }]) {
+ expect((await call(who.alice(), 'recall', params)).all).not.toContain(CANARY.alice);
+ }
+ expect((await call(who.alice(), 'context_pack', { query: 'harbor oolong', entities: [ACME] })).all).not.toContain(CANARY.alice);
+ const [bobFact] = await engine.executeRaw<{ id: number | string }>('SELECT id FROM facts WHERE fact LIKE $1 AND expired_at IS NULL', ['%' + CANARY.bob + '%']);
+ const bobPage = 'memory/members/bob-example';
+ await engine.executeRaw('UPDATE pages SET frontmatter = frontmatter || $3::jsonb WHERE source_id = $1 AND slug = $2', [SRC, bobPage, JSON.stringify(marker)]);
+ try {
+ const forgot = await call(who.bobToken(), 'forget_fact', { id: Number(bobFact!.id) });
+ expect({ isError: forgot.isError, code: forgot.json.code }).toEqual({ isError: true, code: 'fact_not_found' });
+ const [still] = await engine.executeRaw<{ expired_at: unknown }>('SELECT expired_at FROM facts WHERE id = $1', [bobFact!.id]);
+ expect(still!.expired_at).toBeNull();
+ } finally {
+ await engine.executeRaw('UPDATE pages SET frontmatter = frontmatter - $3 WHERE source_id = $1 AND slug = $2', [SRC, bobPage, Object.keys(marker)[0]]);
+ }
+ } finally {
+ await engine.executeRaw('UPDATE pages SET frontmatter = frontmatter - $3 WHERE source_id = $1 AND slug = $2', [SRC, page, Object.keys(marker)[0]]);
+ __resetPrivateVisibilityCacheForTests();
+ __resetHotMemoryCacheForTests();
+ }
+ }
+ expect((await call(who.alice(), 'recall', { query: 'harbor' })).all).toContain(CANARY.alice);
+ }, 120_000);
+
test('another member never reads the fact through the member page, the entity page, search or context_pack', async () => {
for (const as of [who.bob(), who.bobToken(), who.bare(), who.unbound()]) {
for (const [op, params] of [['get_page', { slug: 'memory/members/alice-example' }], ['get_page', { slug: ACME }], ['search', { query: CANARY.alice }],
diff --git a/test/graduation-inventory.test.ts b/test/graduation-inventory.test.ts
index dca98c28bb..57238451b6 100644
--- a/test/graduation-inventory.test.ts
+++ b/test/graduation-inventory.test.ts
@@ -60,7 +60,7 @@ describe('graduation inventory', () => {
expect(new Set(names).size).toBe(names.length);
const counts: Record<string, number> = {};
for (const e of GRADUATION_INVENTORY.entries) counts[e.class] = (counts[e.class] ?? 0) + 1;
- expect(counts).toEqual({ carry: 155, rebind: 2, rebuild: 3, discard: 9, schema_owned: 4 });
+ expect(counts).toEqual({ carry: 156, rebind: 2, rebuild: 3, discard: 9, schema_owned: 4 });
for (const e of GRADUATION_INVENTORY.entries) {
expect({ relation: e.relation, reason: e.reason.length > 5, present: e.engines.pglite || e.engines.postgres })
.toEqual({ relation: e.relation, reason: true, present: true });