Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(access): withFolderRestricted reads only type, frontmatter and the folder rule

garrytaned0548f5b355
diff --git a/src/core/search/private-visibility.ts b/src/core/search/private-visibility.ts
index 008320de14..bb1203849a 100644
--- a/src/core/search/private-visibility.ts
+++ b/src/core/search/private-visibility.ts
@@ -478,8 +478,8 @@ export async function folderRestricted(engine: Pick<BrainEngine, 'executeRaw'>,
}
/** `page` with folder_restricted looked up (folderRestricted), for a page read without it, such as a page snapshot. */
-export async function withFolderRestricted<P extends { source_id: string; slug: string }>(engine: Pick<BrainEngine, 'executeRaw'>, page: P): Promise<P & { folder_restricted: boolean }> {
- return { ...page, folder_restricted: await folderRestricted(engine, page.source_id, page.slug) };
+export async function withFolderRestricted(engine: Pick<BrainEngine, 'executeRaw'>, page: { source_id: string; slug: string; type?: string | null; frontmatter?: unknown }): Promise<{ type?: string | null; frontmatter?: unknown; folder_restricted: boolean }> {
+ return { type: page.type, frontmatter: page.frontmatter, folder_restricted: await folderRestricted(engine, page.source_id, page.slug) };
}
/**
diff --git a/test/folder-restricted-no-body-read.test.ts b/test/folder-restricted-no-body-read.test.ts
new file mode 100644
index 0000000000..0117beff78
--- /dev/null
+++ b/test/folder-restricted-no-body-read.test.ts
@@ -0,0 +1,16 @@
+/**
+ * A2 folder rules: withFolderRestricted reads only what the privacy judgment needs.
+ *
+ * 1. Protects: a segmented page snapshot, whose compiled_truth getter throws, can be judged without reading its body.
+ * 2. Fails when: withFolderRestricted spreads the whole page object again.
+ */
+import { expect, test } from 'bun:test';
+import { withFolderRestricted } from '../src/core/search/private-visibility.ts';
+
+test('withFolderRestricted never reads the page body', async () => {
+ const page = { source_id: 'source-a', slug: 'notes/segmented', type: 'note', frontmatter: { visibility: 'world' } };
+ Object.defineProperty(page, 'compiled_truth', { enumerable: true, get() { throw new Error('segmented body read'); } });
+ const engine = { executeRaw: async () => [] } as never;
+ const out = await withFolderRestricted(engine, page);
+ expect(out).toEqual({ type: 'note', frontmatter: { visibility: 'world' }, folder_restricted: false });
+});