Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 10d63c6c70884c948a0bc868413f07cd065a6633
parent dfe3befd445986900eab94377453f5ea5b5f71ad
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 08:40:04 -0500

x-trending review 1 (S4): three privacy sweeps read the call shapes they guard -- a `listXTrending(…)` call is read to its balanced end, so options after a root built by a call are seen; the MCP's query is read from `new URLSearchParams({…})`, `.set("…")` and a hand-written address, and every key must be slug, topic or limit; each sweep has a test that it catches the forbidden shape

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mcommon/bin/xTrendingPrivacy.test.ts | 47+++++++++++++++++++++++++++++++++++++++++++++--
Mcommon/publish/xTrendingReportDoor.test.ts | 35++++++++++++++++++++++++++++++++++-
Mmcp/src/xTrendingPrivacy.test.ts | 46+++++++++++++++++++++++++++++++++++++++-------
3 files changed, 118 insertions(+), 10 deletions(-)

diff --git a/common/bin/xTrendingPrivacy.test.ts b/common/bin/xTrendingPrivacy.test.ts @@ -256,6 +256,36 @@ test("the search itself catches a leak", () => { const JUDGE_VIEW_ONLY = ["xTrending/purge", "purgeXTrendingDropped", "removeXTrendingPostCapture", "summarizeXTrending", "xTrendingCaptureFiles", "purge-trending"]; + +// Every call of `fn` in a source, with its WHOLE argument text (parentheses balanced, so a call whose +// first argument is itself a call — `listXTrending(path.join(a, b), { detail: true })` — is read to its end). +function callsOf(text: string, fn: string): string[] { + const out: string[] = []; + for (let at = text.indexOf(`${fn}(`); at >= 0; at = text.indexOf(`${fn}(`, at + 1)) { + let depth = 0; + let end = -1; + for (let i = at + fn.length; i < text.length; i++) { + if (text[i] === "(") depth++; + else if (text[i] === ")" && --depth === 0) { + end = i; + break; + } + } + out.push(text.slice(at + fn.length + 1, end < 0 ? text.length : end)); + } + return out; +} + +// The judge view's asks of the listing: no publishing source may make one. +const JUDGE_VIEW_ASKS = /\b(detail|ids|filter|offset|seen)\b\s*[:,}]/; +function judgeViewAsk(text: string): string | null { + for (const args of callsOf(text, "listXTrending")) { + // The options are everything after the first argument (the library's root). + if (JUDGE_VIEW_ASKS.test(args)) return `listXTrending(${args.replace(/\s+/g, " ").slice(0, 120)})`; + } + return null; +} + function sourcesUnder(dir: string): { rel: string; text: string }[] { const out: { rel: string; text: string }[] = []; const walk = (d: string) => { @@ -300,7 +330,20 @@ test("no build, publisher, export, homepage or MCP module reaches the judge view assert.ok(files.length > 50, "the sweep read the publishing sources"); for (const f of files) { for (const word of JUDGE_VIEW_ONLY) assert.ok(!f.text.includes(word), `${path.relative(repo, f.rel)} names ${word}`); - // The listing is asked there with a topic and a limit at most: never the judge view's detail, ids or filter. - if (f.text.includes("listXTrending(")) assert.ok(!/listXTrending\([^)]*\b(detail|ids|filter|offset)\b/.test(f.text), `${path.relative(repo, f.rel)} asks the listing for the judge view's fields`); + // The listing is asked there with a topic and a limit at most: never the judge view's detail, ids, filter or marks. + assert.equal(judgeViewAsk(f.text), null, `${path.relative(repo, f.rel)} asks the listing for the judge view's fields`); } }); + +test("the sweep catches the call shapes it guards against", () => { + // The shape a real caller has: the root built by a call, the options after it, over several lines. + assert.match(judgeViewAsk('const l = await listXTrending(path.join(paths.channelsDir, slug), { detail: true });') ?? "", /detail: true/); + assert.ok(judgeViewAsk("await listXTrending(\n path.join(a, b),\n {\n ...(topic ? { topic } : {}),\n ids: true,\n },\n);")); + assert.ok(judgeViewAsk("listXTrending(root(x), { filter: { state: \"drop\" } })")); + assert.ok(judgeViewAsk("listXTrending(root(x), { limit: 5, offset })")); + assert.ok(judgeViewAsk("listXTrending(root(x), { topic, seen })")); + // What a publishing source may ask: a root, a topic, a limit. + assert.equal(judgeViewAsk("listXTrending(path.join(a, b), { ...(topic ? { topic } : {}), ...(limit !== undefined ? { limit } : {}) })"), null); + assert.equal(judgeViewAsk("listXTrending(libRoot)"), null); + assert.equal(judgeViewAsk("// a comment about detail and ids\nfoo(detail)"), null); +}); diff --git a/common/publish/xTrendingReportDoor.test.ts b/common/publish/xTrendingReportDoor.test.ts @@ -268,6 +268,35 @@ test("N8a: behind such a host, preparing media refuses a library's post, and no ); }); +// Every call of `fn` in a source, with its WHOLE argument text (parentheses balanced, so a call whose +// first argument is itself a call — `listXTrending(path.join(a, b), { detail: true })` — is read to its end). +function callsOf(text: string, fn: string): string[] { + const out: string[] = []; + for (let at = text.indexOf(`${fn}(`); at >= 0; at = text.indexOf(`${fn}(`, at + 1)) { + let depth = 0; + let end = -1; + for (let i = at + fn.length; i < text.length; i++) { + if (text[i] === "(") depth++; + else if (text[i] === ")" && --depth === 0) { + end = i; + break; + } + } + out.push(text.slice(at + fn.length + 1, end < 0 ? text.length : end)); + } + return out; +} + +// The judge view's asks of the listing: no publishing source may make one. +const JUDGE_VIEW_ASKS = /\b(detail|ids|filter|offset|seen)\b\s*[:,}]/; +function judgeViewAsk(text: string): string | null { + for (const args of callsOf(text, "listXTrending")) { + // The options are everything after the first argument (the library's root). + if (JUDGE_VIEW_ASKS.test(args)) return `listXTrending(${args.replace(/\s+/g, " ").slice(0, 120)})`; + } + return null; +} + // Lane posts-library: the judge view's reads (the detail listing) are the one // place a kept post's note and its capture's context are given out. No report // door wrote them, and no report module can ask for them or for the purge. @@ -285,6 +314,10 @@ test("posts-library: the detail listing holds the note and the context; what the for (const word of ["xTrending/purge", "purgeXTrendingDropped", "removeXTrendingPostCapture", "summarizeXTrending", "xTrendingCaptureFiles"]) { assert.ok(!f.text.includes(word), `publish/${f.rel} names ${word}`); } - assert.ok(!/listXTrending\([^)]*\b(detail|ids|filter|offset)\b/.test(f.text), `publish/${f.rel} asks the listing for the judge view's fields`); + assert.equal(judgeViewAsk(f.text), null, `publish/${f.rel} asks the listing for the judge view's fields`); } + // The sweep catches the shape a real caller has (the root built by a call, the options after it). + assert.ok(judgeViewAsk("await listXTrending(path.join(paths.channelsDir, slug), {\n detail: true,\n});")); + assert.ok(judgeViewAsk("listXTrending(root(x), { topic, ids: true })")); + assert.equal(judgeViewAsk("listXTrending(path.join(a, b), { topic, limit })"), null); }); diff --git a/mcp/src/xTrendingPrivacy.test.ts b/mcp/src/xTrendingPrivacy.test.ts @@ -170,22 +170,54 @@ test("every read-only corpus tool over the composed site: the account's post, ne }); // Lane posts-library: the judge view's asks of the editor's listing (detail, -// ids, the filters) and the purge are umtool's and `pnpm ops`'s. The MCP's two -// trending tools ask for a topic and a limit, and gain no purge. +// ids, the filters, the seen marks) and the purge are umtool's and `pnpm +// ops`'s. The MCP's two trending tools ask for a slug, a topic and a limit, and +// gain no purge. +// +// THE MCP BUILDS ITS QUERY WITH `new URLSearchParams({…})` AND `.set("…")`, so +// that is what is read: every key given to either, in a source that asks the +// listing, is one of the three. +const LISTING_KEYS = new Set(["slug", "topic", "limit"]); + +function queryKeys(text: string): string[] { + const keys: string[] = []; + // new URLSearchParams({ a: …, "b": …, c }) + for (const m of text.matchAll(/new URLSearchParams\(\s*\{([^}]*)\}/g)) { + for (const part of m[1].split(",")) { + const key = /^\s*(?:\.\.\.)?["'`]?([A-Za-z_$][\w$]*)["'`]?\s*(?::|$)/.exec(part); + if (key) keys.push(key[1]); + } + } + // q.set("a", …) / q.append("a", …) + for (const m of text.matchAll(/\.(?:set|append)\(\s*["'`]([^"'`]+)["'`]/g)) keys.push(m[1]); + // …and a key written into the address by hand: ?a=… &a=… + for (const m of text.matchAll(/\/api\/ops\/trending\?[^"'`\s]*/g)) for (const k of m[0].matchAll(/[?&]([A-Za-z_]+)=/g)) keys.push(k[1]); + return keys; +} + test("posts-library: no MCP source asks the listing for the judge view's fields, or names the purge", async () => { const { readdirSync, readFileSync } = await import("node:fs"); const here = path.dirname(new URL(import.meta.url).pathname); const sources = readdirSync(here).filter((n) => /\.ts$/.test(n) && !n.includes(".test.")); assert.ok(sources.length > 5, "the MCP's sources were read"); + let asking = 0; for (const name of sources) { const text = readFileSync(path.join(here, name), "utf8"); for (const word of ["purge-trending", "purgeXTrending", "removeXTrendingPostCapture", "/api/library", "judge-trending\"", "watch-trending\""]) { assert.ok(!text.includes(word), `mcp/src/${name} names ${word}`); } - if (text.includes("/api/ops/trending")) { - for (const param of ["detail", "ids", "offset", "author", "since", "state=", "gone", "q="]) { - assert.ok(!new RegExp(`[?&"'\`]${param.replace("=", "")}=|set\\("${param.replace("=", "")}"`).test(text), `mcp/src/${name} asks the listing for ${param}`); - } - } + if (!text.includes("/api/ops/trending")) continue; + asking++; + const keys = queryKeys(text); + assert.ok(keys.includes("slug"), `mcp/src/${name}: the query's keys were read (${keys.join(", ")})`); + for (const key of keys) assert.ok(LISTING_KEYS.has(key), `mcp/src/${name} asks the listing for "${key}"`); } + assert.ok(asking >= 1, "a source that asks the listing was read"); +}); + +test("posts-library: the query sweep catches the shapes it guards against", () => { + assert.deepEqual(queryKeys('const q = new URLSearchParams({ slug: channel, limit: "1" });\nq.set("topic", topic);'), ["slug", "limit", "topic"]); + assert.deepEqual(queryKeys('new URLSearchParams({ slug, detail: "1" })'), ["slug", "detail"]); + assert.deepEqual(queryKeys('q.set("ids", "1"); q.append("seen", marks);'), ["ids", "seen"]); + assert.deepEqual(queryKeys("`/api/ops/trending?slug=${s}&state=drop&by=operator`"), ["slug", "state", "by"]); });