Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(security): fetch withholds a quarantined page's text from untrusted readers, like get_page (#6259)

time-attackc509742f9efc
diff --git a/docs/architecture/key-files/quarantine.md b/docs/architecture/key-files/quarantine.md
index 26ba8a3983..b3ccc94b49 100644
--- a/docs/architecture/key-files/quarantine.md
+++ b/docs/architecture/key-files/quarantine.md
@@ -31,8 +31,10 @@ leave rows projected before it as they are. Tests: `test/facts-eligibility.test.
`persistence/page-prepare.ts`) and one `page_quarantined` safety notice
(`pageQuarantinedNotice`, emitted by `emitFenceNotice` in `page-mutations.ts`;
put_pages marks each page and emits one notice in `page-batch.ts`). get_page
-(`ops/pages.ts`) carries `quarantined` and the notice; an untrusted reader gets
-no body unless it holds `admin` and passes `include_quarantined: true`.
+(`ops/pages.ts`) carries `quarantined` and the notice, and so does `fetch`
+(`metadata.quarantined`, both through `readQuarantined`); an untrusted reader
+gets no body (fetch: empty `text`) unless it holds `admin` and passes
+`include_quarantined: true`.
Test: `test/quarantine-read-write-surface.test.ts`.
- `src/core/quarantine-override.ts` — #6259 (fix wave 12): the `quarantine_override` frontmatter key `gbrain quarantine clear --force` records: `{ binding, cleared_at }`, where `binding` is a sha256 over the classifier's inputs (title, type, body) as the gate canonicalizes them (`quarantineOverrideFor`). `assessImportSanity` (`import-screen.ts`) wraps its verdict in `withQuarantineOverride`, which removes the junk-pattern, literal and markup-flag outcomes while the binding is current (size outcomes stay). `importFromContent` calls `stripGateOwnedMarkers` (`import-screen.ts`, `GATE_OWNED_FRONTMATTER_KEYS`): every writer loses `quarantine`, `content_flag`, `embed_skip`, `atoms_scan_hash` and `quarantine_override` unless an owner-tier path passes `preserveGateMarkers: true` (`importFromFile`, managed sync and file import, reindex, file repair, reconcile, the cycle derivers and their `managed_maintenance_page` intents, `quarantine clear/scan` and the owner-internal `managed_quarantine_clear` put_page kind); local put_page, connectors and ingest lanes do not. A preserving path keeps its own override only while current, and a current override drops classifier markers the content still carries. `opts.remote` keeps only its fence-merge/hidden-row meaning. Tests: `test/gate-marker-strip.test.ts`. For a stripped write the classifier would hide or markup-flag, `carryStoredQuarantineOverride` reads the stored override and keeps it when it still binds (so a remote tag edit does not re-hide the page); a clean remote write reads nothing extra (#6007 statement budget). Company-brain inspection refuses files carrying it (`hidden_input`). Doctor's quarantine row names `clear <slug> --force` and `content_sanity.disabled_patterns`.
diff --git a/docs/mcp/CHATGPT.md b/docs/mcp/CHATGPT.md
index b646fd9d77..59d65aa510 100644
--- a/docs/mcp/CHATGPT.md
+++ b/docs/mcp/CHATGPT.md
@@ -125,7 +125,10 @@ chat: the server must expose a `search`/`fetch` tool PAIR, where every
URI for the citation slot, and `metadata` carries type/source/tags.
`fetch` is a thin read-only adapter over the same page read as `get_page`
-(same source scoping, same privacy fences for remote readers). Normal chat
+(same source scoping, same privacy fences for remote readers). A page the
+content-quality gate quarantined comes back with `metadata.quarantined` and a
+`page_quarantined` notice; for a remote caller `text` is empty unless an
+admin-scoped caller passes `include_quarantined: true`. Normal chat
keeps using the richer gbrain-native tools; deep research uses the pair.
An ID does not grant access: fetch rechecks current source grants and page
visibility. Legacy bare-slug IDs still work when unambiguous within the current
diff --git a/src/core/behavior-change-notice.ts b/src/core/behavior-change-notice.ts
index 5a080c374d..e16964e830 100644
--- a/src/core/behavior-change-notice.ts
+++ b/src/core/behavior-change-notice.ts
@@ -305,7 +305,7 @@ export const BEHAVIOR_CHANGES: ReadonlyArray<{ since: string; text: ChangeText }
{ since: '0.60.106.0', text: '`gbrain reindex --markdown` asks before re-embedding (paid): without a terminal it exits 3 with an ask_user payload naming the page count, the estimate and the `--yes` command; `--yes` or `--max-usd <usd>` approves it, and `--dry-run`, `--no-embed` and a keyless brain never ask. A queued `reindex` job re-embeds only with the approval stored at submit time (`gbrain jobs submit reindex ... --yes`, or the search-mode switch prompt); one queued without it fails with `confirmation_required`.' },
{ since: 'NEXT', text: 'Search-hiding and other gate-owned frontmatter keys (`quarantine`, `content_flag`, `embed_skip`, `atoms_scan_hash`, `quarantine_override`) in a local `put_page`, a connector, an ingest event or any other non-owner write are now stripped instead of kept; sync and import of your own files, reindex, repair and `gbrain quarantine clear` keep them.' },
{ since: 'NEXT', text: 'A quarantined page is no longer offered to automatic fact extraction (`facts_backstop.skipped: quarantined`) and its facts and takes fences are not projected; rows projected before it was quarantined stay.' },
- { since: 'NEXT', text: '`get_page` of a quarantined page carries `quarantined` and a `page_quarantined` notice, and remote callers get no body unless an admin-scoped caller passes `include_quarantined: true`; a quarantined `put_page` now reports `quarantined: { reason, detail }`.' },
+ { since: 'NEXT', text: '`get_page` and `fetch` of a quarantined page carry `quarantined` (fetch: `metadata.quarantined`) and a `page_quarantined` notice, and remote callers get no body or text unless an admin-scoped caller passes `include_quarantined: true`; a quarantined `put_page` now reports `quarantined: { reason, detail }`.' },
];
/** The newest disclosed change's release: the notice id moves only when a release adds rows. */
diff --git a/src/core/ops/pages.ts b/src/core/ops/pages.ts
index f3c0f069a2..a7e0e840a6 100644
--- a/src/core/ops/pages.ts
+++ b/src/core/ops/pages.ts
@@ -221,6 +221,7 @@ const fetch_page: Operation = {
description: "Fetch the full text of one search result by its opaque, source-qualified `id` (OpenAI deep-research contract: the search/fetch pair). Pass the id unchanged; it does not grant access. Legacy slug ids work only when unambiguous within your current read scope. Returns { id, title, text, url, metadata } — `text` is the page's canonical markdown. For fuzzy slugs, soft-delete recovery, or lossless edit round-trips, use get_page.",
params: {
id: { type: 'string', required: true, description: 'Opaque result id from a prior `search` call. Pass unchanged. Unambiguous legacy slugs are also accepted.' },
+ include_quarantined: { type: 'boolean', description: 'Admin: quarantined body.' },
},
handler: async (ctx, p) => {
const id = p.id as string;
@@ -261,15 +262,13 @@ const fetch_page: Operation = {
if (!page || (excludePrivate && isPrivatePage(page))) throw missing();
bumpLastRetrievedAt(ctx.engine, [page.id]);
const tags = snapshot!.tags;
- // Same privacy boundary as get_page: untrusted readers (ctx.remote ===
- // true — every MCP transport) never see takes or private facts fences.
- const visibleBody = ctx.remote === false
- ? page
- : stripPrivacyFencesForRemoteReader(page);
+ // Same boundaries as get_page: untrusted readers never see takes or private facts fences, nor a quarantined body (#6259).
+ const visibleBody = ctx.remote === false ? page : stripPrivacyFencesForRemoteReader(page);
+ const quarantined = readQuarantined(ctx, page, p.include_quarantined === true);
return {
id: identity ? id : page.slug,
title: page.title,
- text: serializePageToMarkdown(visibleBody as Page, tags),
+ text: quarantined?.body_omitted ? '' : serializePageToMarkdown(visibleBody as Page, tags),
// Pages have no public http home; a stable brain-local URI satisfies
// the contract's citation slot without inventing a fake web URL.
url: deepResearchPageUrl(page.source_id, page.slug),
@@ -278,7 +277,7 @@ const fetch_page: Operation = {
type: page.type,
source_id: page.source_id,
updated_at: page.updated_at,
- tags,
+ tags, ...(quarantined ? { quarantined } : {}),
},
};
},
diff --git a/test/quarantine-read-write-surface.test.ts b/test/quarantine-read-write-surface.test.ts
index dbc7f82004..9b4ce9079a 100644
--- a/test/quarantine-read-write-surface.test.ts
+++ b/test/quarantine-read-write-surface.test.ts
@@ -97,3 +97,35 @@ describe('get_page of a quarantined page (#6259 item 4)', () => {
expect(String(page.compiled_truth)).toContain('Ordinary prose');
}));
});
+
+describe('fetch of a quarantined page (#6259, same policy as get_page)', () => {
+ const fetchPage = (c: OperationContext, extra: Record<string, unknown> = {}) =>
+ op('fetch').handler(c, { id: 'notes/junk-write', ...extra }) as Promise<{ text: string; metadata: Record<string, unknown> }>;
+
+ test('a trusted local fetch keeps the text, with metadata.quarantined and a notice', () => withEnv(env, async () => {
+ const notices: Notice[] = [];
+ const result = await fetchPage(ctx({ notices }));
+ expect(result.text).toContain('Cloudflare Ray ID');
+ expect(result.metadata.quarantined).toMatchObject({ reason: 'junk_pattern', body_omitted: false });
+ expect(notices.map(n => n.code)).toEqual(['page_quarantined']);
+ }));
+
+ test('an untrusted fetch gets no text, even when a non-admin asks', () => withEnv(env, async () => {
+ for (const extra of [{}, { include_quarantined: true }]) {
+ const notices: Notice[] = [];
+ const result = await fetchPage(ctx({ remote: true, scopes: ['read'], notices }), extra);
+ expect(result.text).toBe('');
+ expect(result.metadata.quarantined).toMatchObject({ body_omitted: true });
+ expect(JSON.stringify(result)).not.toContain('Cloudflare Ray ID: 8f2a');
+ expect(notices[0]!.why).toContain('include_quarantined: true');
+ }
+ }));
+
+ test('an admin-scoped untrusted caller gets the text only when it asks; a clean page is unchanged', () => withEnv(env, async () => {
+ expect((await fetchPage(ctx({ remote: true, scopes: ['admin'] }))).text).toBe('');
+ expect((await fetchPage(ctx({ remote: true, scopes: ['admin'] }), { include_quarantined: true })).text).toContain('Cloudflare Ray ID');
+ const clean = await op('fetch').handler(ctx({ remote: true, scopes: ['read'] }), { id: 'notes/clean-write' }) as { text: string; metadata: Record<string, unknown> };
+ expect(clean.text).toContain('Ordinary prose');
+ expect(clean.metadata.quarantined).toBeUndefined();
+ }));
+});