From af0f23d09d205fa7a9739f47aff8fe2fb4738737 Mon Sep 17 00:00:00 2001 From: ozymandiashh <234437643+ozymandiashh@users.noreply.github.com> Date: Mon, 14 Sep 2026 12:44:48 +0300 Subject: [PATCH] fix(sharing,mcp): drop or pseudonymize pull request rows in redacted payloads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit current.pullRequests survived both sanitizeForSharing and redactProjectNames(include_project_names: false) verbatim, so each row's full GitHub url and owner/repo#123 label named the repository to a paired peer device and to a name-redacted MCP client — the same class of leak Sharing drops the block like it drops the project, session and per-branch rows. The MCP pass pseudonymizes url and label from the url (the aggregation key) with the same salted, domain-separated hash as the other pseudonyms, so rows referring to the same PR still line up and every number stays untouched. Closes #1346 --- CHANGELOG.md | 1 + src/mcp/redact.ts | 20 ++++++++++++++++++++ src/sharing/sanitize.ts | 4 +++- tests/mcp-redact.test.ts | 26 ++++++++++++++++++++++++++ tests/sharing/sanitize.test.ts | 16 ++++++++++++++++ 5 files changed, 66 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 369f070d..005c8f08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ ### Fixed - **Codex sub-agent rollouts no longer double-count their parent's usage.** A thread spawned as a sub-agent replays its parent's history, including every `token_count` event with its original timestamp, and names the parent under `source.subagent.thread_spawn.parent_thread_id` rather than `forked_from_id`, so the fork guard never saw it and the replayed prefix was counted again per child. The parent id is now read from either field, and the replayed events drop like a fork's. On a corpus with 381 spawned children this removed 405 duplicate calls and 403,712 duplicate cache tokens; rollouts without sub-agents are unchanged. (#1380) +- **Shared and MCP-redacted payloads no longer carry pull request urls or owner/repo labels.** `current.pullRequests` survived both passes verbatim: each row's full GitHub url and its `owner/repo#123` label named the repository to a paired peer device and to a name-redacted MCP client, the same class of leak #1337 closed for branch names. Sharing now drops the block outright, the way it already drops the project, session and per-branch rows. The MCP pass with `include_project_names: false` pseudonymizes `url` and `label` from the url — the aggregation key — with the same salted hash as the project and branch pseudonyms, domain-separated so rows referring to the same PR still line up while the cost, calls and totals stay untouched; `include_project_names: true` still sees the real urls and labels. (#1346) - **The menubar refreshes usage within five minutes while a session is running, instead of up to thirty.** The background change guard only stats directories, so a session appending to its transcript looked unchanged and the app skipped every refresh for half an hour; the skip now lasts at most five minutes, and the Kimi Code session store joined the watched roots. - **The Capacity Dock card lists running sessions for providers whose CLI id differs from the dock id.** The card matched live rows against the dock's own identifier ("kimi"), while the CLI reports "kimicode", so a running Kimi Code session read "none running"; the card now matches the provider's payload ids, which also lets the Cursor card count cursor-agent sessions. - **Shared and MCP-redacted payloads no longer carry git branch names or the working directory of a session.** Two identities were riding along in `current`: the `topSessions` rows added in #1316 carry `projectKey`, a dash-encoded absolute path such as `-Users--Projects-`, which `redactProjectNames` left verbatim even when an MCP client asked not to see project names, and the per-branch rows added in #788 carry the raw branch, which both `sanitizeForSharing` and the MCP pass let through, so a branch such as `exp/extraction-arms` reached a shared payload as typed. The MCP pass now hashes `projectKey` with the same salted pseudonym it already applies to `topProjects[].id`, hashes the drill-through `sessionId` on both `topSessions` and `topProjects[].sessionDetails` (a Codex id embeds the rollout timestamp the pass blanks out of `date`), and gives each distinct branch a stable `branch-xxxxxx` pseudonym, keeping the cost, calls and session counts untouched; a `null` branch stays null, because unbranched spend is not a name. Sharing drops the per-branch block outright, the way it already drops the project and session rows, since a pseudonymized branch tells a peer device nothing anyway. Nothing changes for the local menubar, the desktop app or the web dashboard, which read the unsanitized payload, and nothing changes for an MCP caller that passes `include_project_names: true` — it still gets every name as recorded. (#1325, #1321) diff --git a/src/mcp/redact.ts b/src/mcp/redact.ts index d406114c..73e0379c 100644 --- a/src/mcp/redact.ts +++ b/src/mcp/redact.ts @@ -46,6 +46,14 @@ function sessionPseudonym(id: string): string { return `session-${hashed(`session:${id}`)}` } +/// PR rows name the repository in both the full URL (the aggregation key) and +/// the `owner/repo#123` label, so a caller that asked not to see project names +/// must not see them either. Pseudonymized from the URL so rows referring to +/// the same PR still line up; the numbers stay untouched. +function prPseudonym(url: string): string { + return `pr-${hashed(`pr:${url}`)}` +} + type SessionDetails = MenubarPayload['current']['topProjects'][number]['sessionDetails'] function redactSessionDetails(details: SessionDetails): SessionDetails { @@ -91,6 +99,18 @@ export function redactProjectNames(payload: MenubarPayload, includeNames: boolea })), } : {}), + ...(payload.current.pullRequests + ? { + pullRequests: { + ...payload.current.pullRequests, + rows: payload.current.pullRequests.rows.map(row => ({ + ...row, + url: prPseudonym(row.url), + label: prPseudonym(row.url), + })), + }, + } + : {}), }, history: { ...payload.history, diff --git a/src/sharing/sanitize.ts b/src/sharing/sanitize.ts index a08903ed..a27398a2 100644 --- a/src/sharing/sanitize.ts +++ b/src/sharing/sanitize.ts @@ -16,7 +16,9 @@ export function sanitizeForSharing(payload: MenubarPayload): MenubarPayload { // Per-branch rows are keyed by the raw git branch, which encodes ticket ids, // customer names and feature codenames as readily as a project name does, so // they leave with the project and session rows rather than travelling verbatim. - const { byBranch: _byBranch, ...current } = payload.current + // PR rows carry the repository owner and name in both the full URL and the + // `owner/repo#123` label, so they travel with them. + const { byBranch: _byBranch, pullRequests: _pullRequests, ...current } = payload.current return { ...rest, current: { diff --git a/tests/mcp-redact.test.ts b/tests/mcp-redact.test.ts index 9b70d4a0..468a0942 100644 --- a/tests/mcp-redact.test.ts +++ b/tests/mcp-redact.test.ts @@ -34,6 +34,15 @@ function payload(): MenubarPayload { { branch: 'exp/extraction-arms', cost: 4, calls: 8, sessions: 1 }, { branch: null, cost: 1, calls: 2, sessions: 1 }, ], + pullRequests: { + rows: [{ + url: 'https://github.com/secret-client/repo/pull/42', label: 'secret-client/repo#42', + cost: 4, savingsUSD: 0, sessions: 1, calls: 8, + firstStarted: '2026-06-01T10:00:00.000Z', lastEnded: '2026-06-01T12:00:00.000Z', + approx: false, models: ['Opus'], + }], + distinctCost: 4, distinctSessions: 1, attributedCost: 4, unattributedCost: 0, + }, retryTax: { totalUSD: 0, retries: 0, editTurns: 0, byModel: [] }, routingWaste: { totalSavingsUSD: 0, baselineModel: '', baselineCostPerEdit: 0, byModel: [] }, tools: [], skills: [], subagents: [], mcpServers: [], @@ -101,6 +110,21 @@ describe('redact', () => { const second = redactProjectNames(payload(), false).current.byBranch![0]!.branch expect(first).toBe(second) }) + it('pseudonymizes PR urls and labels but keeps the numbers', () => { + const out = redactProjectNames(payload(), false) + const row = out.current.pullRequests!.rows[0]! + expect(row.url).toMatch(/^pr-[0-9a-f]{6}$/) + expect(row.label).toBe(row.url) + expect(row.cost).toBe(4) + expect(row.calls).toBe(8) + expect(JSON.stringify(out)).not.toContain('github.com/secret-client/repo') + expect(JSON.stringify(out)).not.toContain('secret-client/repo#42') + }) + it('gives the same PR the same pseudonym across calls, distinct from other PRs', () => { + const first = redactProjectNames(payload(), false).current.pullRequests!.rows[0]!.url + const second = redactProjectNames(payload(), false).current.pullRequests!.rows[0]!.url + expect(first).toBe(second) + }) it('same project name gets same pseudonym in topProjects and topSessions', () => { const out = redactProjectNames(payload(), false) expect(out.current.topProjects[0]!.name).toBe(out.current.topSessions[0]!.project) @@ -120,6 +144,8 @@ describe('redact', () => { expect(out.current.topSessions[0]!.sessionId).toBe(RAW_SESSION_ID) expect(out.current.topProjects[0]!.name).toBe('secret-client-repo') expect(out.current.topProjects[0]!.sessionDetails![0]!.date).toBe('2026-06-01') + expect(out.current.pullRequests!.rows[0]!.url).toBe('https://github.com/secret-client/repo/pull/42') + expect(out.current.pullRequests!.rows[0]!.label).toBe('secret-client/repo#42') expect(out.history.timeline?.sessionSeries[0]!.label).toContain('secret-client-repo') }) it('drops the live-session block even when names are included', () => { diff --git a/tests/sharing/sanitize.test.ts b/tests/sharing/sanitize.test.ts index bf7cc41d..0ba99d1a 100644 --- a/tests/sharing/sanitize.test.ts +++ b/tests/sharing/sanitize.test.ts @@ -28,6 +28,15 @@ function fixture(): MenubarPayload { { branch: 'exp/extraction-arms', cost: 60, calls: 3, sessions: 1 }, { branch: null, cost: 40, calls: 2, sessions: 1 }, ], + pullRequests: { + rows: [{ + url: 'https://github.com/secret-client/repo/pull/42', label: 'secret-client/repo#42', + cost: 60, savingsUSD: 0, sessions: 1, calls: 5, + firstStarted: '2026-06-01T10:00:00.000Z', lastEnded: '2026-06-01T12:00:00.000Z', + approx: false, models: ['Opus'], + }], + distinctCost: 60, distinctSessions: 1, attributedCost: 60, unattributedCost: 0, + }, }, history: { daily: [], @@ -77,6 +86,13 @@ describe('sanitizeForSharing', () => { expect(JSON.stringify(clean)).not.toContain('-Users-me-Projects-secret-project') }) + it('drops the pull-request rows: their urls and labels name the repository', () => { + const clean = sanitizeForSharing(fixture()) + expect(clean.current.pullRequests).toBeUndefined() + expect(JSON.stringify(clean)).not.toContain('github.com/secret-client/repo') + expect(JSON.stringify(clean)).not.toContain('secret-client/repo#42') + }) + it('drops the live-session block, which names the project and branch in flight', () => { const withSessions = { ...fixture(),