Repository navigation
Conversation
…cols WHY: When a conversation switches upstream slots/accounts (failover, sticky reset, or admin sticky delete), stale outbound session headers, foreign thinking blocks, account-scoped tool IDs, and internal SHM/session paths can leak across accounts. Reconciles session-switch purification cleanly atop #2472 without conflicting with src/lib/identity/tool-id-mapping.mjs. CHANGES: - src/lib/identity/session-switch-purify.mjs: HKDF-SHA256 Feistel account-isolated tool ID mapping, internal SHM/CRAG path sanitization, and outbound session switch purification helpers (distinct from #2472 tool-id-mapping.mjs) - src/lib/identity/identity-rewrite.mjs, src/lib/pool/{sticky-router,failover-runner,thinking-owner}.mjs, src/lib/db/repos/sticky-repo.mjs, src/lib/protocol/{handle-protocol,issued-tool-replay}.mjs, src/lib/admin/scheduler-pools-routes.mjs, src/lib/scheduler/scheduler-runtime.mjs, src/lib/transport/go-worker-client.mjs: wire generation >= 2 purification on slot switch / sticky deleteByFilter across protocols - test/unit/{agent-summary-routing,go-worker-client,identity-rewrite,sticky-router}.test.mjs: regression coverage (0 new test files) VERIFIED: - find src scripts -name '*.mjs' | xargs -n1 node --check: PASS - npx biome check (15 files): 0 fixes - KIN_SCHEDULER_BIN=... npm run test:ci: 13/13 PASS - node --test agent-summary-routing go-worker-client identity-rewrite sticky-router slot-machine-env: 202/202 PASS
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: 09df36ed-b506-4d13-b2f0-6562b07448dc) |
…/M9/M10 invariants
1. 本次改动与原因(Head
|
There was a problem hiding this comment.
Agentic security review found two medium isolation gaps in session-switch purification: CRAG thread/diagnostics (and prompt/request correlators) are still stripped only on the first slotSwitched hop, and # userEmail replacement fails for typical dotted addresses when rewriting onto the target slot.
Sent by Cursor Security Agent: Security Reviewer
| if (slotSwitched) { | ||
| if ('thread' in body && body.thread != null) { | ||
| delete ensureBodyCopy().thread | ||
| } | ||
| if ('diagnostics' in body && body.diagnostics != null) { | ||
| delete ensureBodyCopy().diagnostics | ||
| } | ||
| } |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
thread / diagnostics 只在 slotSwitched === true 时被删掉。粘性 reset / failover 的第一跳(freshSlot 或 ledger explicitReset)会打上 slotSwitched,但 commitSlotHop 后 generation >= 2 的后续跳只会走 sessionPurified。同一套路里 purifyCragCallerHeaders 也只在 slotSwitched 时重签 x-claude-code-prompt-id / x-client-request-id。
客户端在切槽后继续上送旧 thread.continue 时,前一槽的 CRAG 会话与 tool 状态可以被重新挂上,使本次会话切换净化失效。
Reviewed by Cursor Security Reviewer for commit 5198ee3. Configure here.
| if (cleanTarget) { | ||
| return reminder.replace( | ||
| /(# userEmail\r?\nThe user's email address is )([^\s.\r\n]+@[^\s.\r\n]+)(\.?)/g, | ||
| (_, p1, _old, p3) => `${p1}${cleanTarget}${p3}`, | ||
| ) |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
目标槽有 email 时,# userEmail 替换正则 [^\s.\r ]+@[^\s.\r ]+ 禁止 local-part 和 domain 出现 .。真实地址(含 user.name@gmail.com 这类)匹配不上,前一槽的 email 会原样留在 <system-reminder> 里转发给新账号。
生产路径会把 VM claude.email 作为 targetEmail 传入,走的正是这条替换分支;现有单测只覆盖空 targetEmail 的整段删除路径。
Reviewed by Cursor Security Reviewer for commit 5198ee3. Configure here.




1. 本次改动与原因
整理本地未提交工作树 eat/session-switch-purify 并与 #2472(eat/slot-machine-env)对齐去重:
2. 已执行验证与结果
px biome check(全部 15 个变更文件)— 0 fixes
ode --test test/unit/agent-summary-routing.test.mjs test/unit/go-worker-client.test.mjs test/unit/identity-rewrite.test.mjs test/unit/sticky-router.test.mjs test/unit/slot-machine-env.test.mjs — 202/202 PASS(0 fail,0 新建测试文件)
3. 破坏性验证(Broken-by-hand)
4. 未运行项
5. 风险与回滚
Note
High Risk
Touches core request routing, sticky session binding, and outbound identity/session IDs—errors could break continuity, tool replay, or leak cross-account state.
Overview
Adds session-switch purification so when a conversation hops to another VM/account, fails over, or has sticky bindings deleted, outbound state does not leak from the previous slot.
A new
session-switch-purifymodule provides account-scoped Feistel tool ID encode/decode (inbound remap + outbound SSE/message restore), payload scrubbing (thread/diagnostics, foreignextension/_kinAccountId,# userEmailand internal paths), a bounded purify ledger for slot lineage, and foreign-tool ownership tracking.Identity and worker path:
resolveOutboundSessionIdnow requires same VM and account to reuse a bound session; slot switches mint fresh sessions (including under passthrough). CRAG caller headers get purified parent/session/prompt/request IDs viapurifyCragCallerHeaders.Sticky and admin:
StickyRouter.deleteByFilter+StickyRepo.removeByFilterpurge bindings and set reset tombstones so the next bind forces generation ≥ 2 and full purification. Scheduler/panel sticky DELETE also clears the purify ledger and returnspurify_ledger_purged.Request pipeline:
handle-protocoldetects slot/account changes, foreign tools, and post-reset generations; on switch it aggressively strips foreign thinking, runspurifySessionPayloadForSlot, and threadsslotSwitched/sessionPurifiedthrough CRAG, CLI, and HTTP hops.failover-runnerinspects/commits the ledger around each attempt.Tests cover Feistel round-trips, sticky delete + ledger purge, header purification, and a multi-protocol end-to-end slot-switch scenario.
Reviewed by Cursor Bugbot for commit 5198ee3. Configure here.