Repository navigation
Conversation
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: 0eaa20fb-b040-4564-a121-e537eb30ffc9) |
| for (const claudeJsonPath of [ | ||
| path.join(slotDir, 'cli-home', '.claude.json'), | ||
| path.join(slotDir, 'cli-home', '.claude', '.claude.json'), | ||
| ]) { | ||
| try { | ||
| if (!fs.existsSync(claudeJsonPath)) continue | ||
| const parsed = JSON.parse(fs.readFileSync(claudeJsonPath, 'utf8')) | ||
| if (parsed && typeof parsed === 'object') { | ||
| delete parsed.oauthAccount | ||
| delete parsed.userID | ||
| delete parsed.machineID | ||
| atomicWriteJson(claudeJsonPath, parsed, { mode: 0o600 }) |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
清凭证路径新增对 cli-home/.claude.json 与 cli-home/.claude/.claude.json 的读写,但未复用 assertSafeSlotCredentialPaths / lstat 防止目录软链跟随。atomicWriteJson 会在父目录写入临时文件再 renameSync,若 .claude 或 cli-home 被替换为绝对路径软链,会跟随该链接。
Impact: 槽内可写进程可把 .claude 指向宿主目录;运维之后调用 POST /api/panel/vms/:id/credential/clear 时,高权限网关进程会在槽目录外创建/覆盖 .claude.json 及临时文件。同 PR 里凭证写入路径已封锁该类遍历。
Reviewed by Cursor Security Reviewer for commit 2b9206f. Configure here.
…isolation
## 变更摘要
- 改前:
- 单槽机器特征缺乏面向真实 `darwin` / `win32` / `linux` 物理设备的确定性画像派生,跳过初始化引导的槽位易缺少配置子目录 `.claude.json` 与稳定 64-hex `device_id`;凭证与内核配置未能以统一脱敏画像联合下发。
- 网关请求/响应/SSE 链路未按账号槽位执行 CWD 路径语法、Git persona/SHA、tool_use ID 与会话 UUIDv4 的四模块双向隔离;跨槽容灾切换与换号/重建/删粘性时缺少对 `slotEpoch`、`issuedTools`、遥测残留与内核重置接口的联动清理。
- 改后:
- 新增 4 个独立身份隔离模块(`src/lib/identity/{slot-machine-profile,cwd-mapping,git-persona,tool-id-mapping}.mjs`)及对应单测(`test/unit/slot-machine-env.test.mjs`):内嵌三平台物理硬件/SMBIOS/系统目录,以账号绑定 HMAC-SHA256 确定性派生 `machine_profile`(`toPublicSlotMachineProfile` 剥离全部私有种子与非 Linux 键;`projectProfileToVmFingerprint` 保留既有容器账号 `username`),提供 8 类路径语法双向映射与分块安全的 SSE 流式重写、8 轮平衡 Feistel Git SHA/persona 映射,以及可逆 `toolu_*` 置换与按账号/槽位/代次隔离的 RFC 4122 UUIDv4 会话 ID。
- 面板与槽位下发链路(`oauth-credentials.mjs`、`rust-kernel-supervisor.mjs`、`remote-slot-files.mjs`、`slot-host.mjs`、`slot-seed.mjs`、`workstation-profile.mjs`、`panel-api.mjs`、`vm-registry.mjs`、`vm-identity.mjs`)实现 `credentials.json` + `run/kernel.json` 脱敏画像联合下发、双路径 `.claude.json` 同步写入、Custom-EROFS KVM `kernel_config` 推送,以及面板安全展示三平台硬件特征(不暴露密钥种子与邮箱)。
- 网关协议与生命周期链路(`handle-protocol.mjs`、`go-worker-client.mjs`、`issued-tool-replay.mjs`、`import-commit.mjs`、`rust-kernel-client.mjs`、`vm-recreate.mjs`、`panel-routes.mjs`、`scheduler-pools-routes.mjs`、`server.mjs`)接入单跳深拷贝四模块正向/非流式/SSE 逆向流水线(保留空 `partial_json: ""` 帧、严禁触碰 `thinking`/`signature` 块、默认 `foreign_only` 跨槽签名剥离),并在换号、槽位重建、清凭证与删除调度粘性时联动清理残留、推进 `slotEpoch`、清空 `issuedTools` 并按能力协商调用 `POST /internal/v1/slot/reset`。
- 未改 / 延后:
- 配套 CRAG 内核变更由独立内核 PR 推进;`deploy/payload.json` 钉选将在内核签名版本发布后单独跟进。本 PR 所有新增内核交互均通过 `slot_machine_profile_v1` / `crag_slot_reset_v1` 能力门控,完全向后兼容 `crag-v2 <= 5.0.0`。
## 验收记录(Run)
- 环境与基线:WSL2 Linux / Node 22 ESM,rebased on `origin/dev` `f19435276`
- 已跑命令与结果:
- `find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check`: PASS (exit 0)
- `npx biome check <28 changed/added files>`: PASS (Checked 28 files, 0 issues)
- `KIN_SCHEDULER_BIN=<temp>/kin-scheduler npm run test:ci`: PASS (13/13 isolated suites)
- `node --test test/unit/slot-machine-env.test.mjs test/unit/oauth-credentials.test.mjs test/unit/go-worker-client.test.mjs test/unit/panel-public-boot.test.mjs test/unit/scheduler-m1b-pools-api.test.mjs test/unit/agent-summary-routing.test.mjs`: PASS (158/158 tests, 0 fail)
## 回退与手破验证(Broken by hand)
- 省略 `credentials.json` 中的 `machineProfile`(`src/lib/oauth/oauth-credentials.mjs`) -> `node --test test/unit/oauth-credentials.test.mjs` FAIL(`31 pass, 1 fail`,`TypeError: Cannot read properties of undefined (reading 'device_id')`) -> 恢复后 PASS(`32/32`)
- 旁路 `mapToolUseIdForAccount` 原样透传(`src/lib/identity/tool-id-mapping.mjs`) -> `node --test test/unit/slot-machine-env.test.mjs` FAIL(`13 pass, 2 fail`,`ERR_ASSERTION` 捕获未置换 `toolu_01...`) -> 恢复后 PASS(`15/15`)
- 旁路 `cwd-mapping.mjs` SSE 分块边界缓冲 `findSafeFlushCut`(`src/lib/identity/cwd-mapping.mjs`) -> `node --test test/unit/slot-machine-env.test.mjs` FAIL(`14 pass, 1 fail`,1 字符分块流漏还原路径触发 `ERR_ASSERTION`) -> 恢复后 PASS(`15/15`)
## 真实使用(Real use)
- 已在隔离沙箱中使用本地构建的真实 `kin-scheduler` 二进制跑通 13/13 CI 隔离套件及网关四模块单跳正向/分块 SSE 逆向、双路配置下发、换号与删粘性重置回归。
- 未执行真实线上生产槽位联调:需待配套 CRAG 内核 PR 合入并发布签名载荷后,再钉选 `deploy/payload.json` 进行单槽验收。
## 未运行项(Not run)
- 全量 554 个后端单测(`npm run test:unit`):本次仅运行 13/13 `test:ci` 隔离套件与全部直接关联回归套件(158 项测试)。
- 前端单测/类型检查/构建(`web/`):本 PR 未触碰前端文件。
- Go / Python / ARM64 交叉构建与真实线上槽位端到端验证:本 PR 未改动 Go/Python 模块,真实内核端到端验证待配套 CRAG 内核发版后跟进。
…agent, count_tokens, and SSE hex flush
## 变更摘要
- **7 表面物理身份同步与重绑闭环**:补齐 KVM/Docker 槽位在 `rebind`、`vm-recreate`、`import-commit`、`panel-routes`、时区持久化与集群远端文件推送中的 7 表面物理指纹同步(`slot-machine-profile`、`official-fingerprint`、`slot-computer`、`vm-identity`、`workstation-profile`、`guest-identity`、`kvm-machine`、`slot-host`、`vm-package`、`remote-slot-files`);并在 `vm-registry.mjs` `persistVmTimezone` 中使用 `replaceSlotOwnedFile` + `sealWorkerCredentialFile` 保持 `credentials.json`(`0o444`)与 `kernel.json` 的槽位属主及读权限。
- **KVM Guest Agent 槽位状态清理与同步**:扩展 `docker/kin-kvm/guest/kin-slot-agent` 与 `src/lib/vm/kvm-slot-agent-client.mjs`,支持 `clear_slot_state`(按白名单清理 `cli-home` 双路径 `.claude.json`、`projects/` 等会话态,保留凭据)及物理身份/时区同步,补充 12 项 Python 单元测试(`test_kin_slot_agent.py`)。
- **协议层 `count_tokens` 与 SSE hex-tail 映射修复**:对齐 `src/lib/protocol/user-count-tokens.mjs` 与 `src/lib/protocol/handle-protocol.mjs`,在 `count_tokens` 预检中只读复用既有完整 `machine_profile`、同步映射 `safeguards[].tool_use_ids` 及 `safeguards[].classifier_context.prior_turn_context[].tool_use_ids`,并修正 SSE 流式 `tool_use_id` hex 尾部缓冲冲洗与 `rust-kernel-supervisor` / `go-worker-client` 透传。
- **未改 / 延后**:配套 CRAG 内核改造在独立内核 PR 推进,`deploy/payload.json` 钉选待内核发版后跟进;`vm2api` 保持 `slot_machine_profile_v1` / `crag_slot_reset_v1` 能力门控并向后兼容 `crag-v2 <= 5.0.0`。
## 验收记录(Run)
- Rebase 基线:`origin/dev` (`744e93091`),0 冲突。
- 语法检查:`find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check` -> PASS(exit 0)。
- 代码格式检查:`npx biome check`(全部 25 个变更 `.mjs` 文件)-> PASS(`Checked 25 files in 1409ms. No fixes applied.`)。
- Python KVM Agent:`python3 -m py_compile docker/kin-kvm/guest/kin-slot-agent && python3 -m unittest discover -s docker/kin-kvm/guest -p test_kin_slot_agent.py -v` -> PASS(`Ran 12 tests in 7.468s`, OK)。
- CI 隔离测试:`npm run test:ci` -> PASS(13/13 套件全过,exit 0)。
- 目标单测(9 套件,`slot-machine-env`、`official-fingerprint`、`guest-identity`、`oauth-credentials`、`go-worker-client`、`vm-recreate`、`kvm-docker-parity`、`kvm-crag-subscription`、`user-count-tokens` 含 `L2-12`)-> PASS(232/232 通过,0 失败)。
## 回退与手破验证(Broken by hand)
1. **K1(`src/lib/identity/slot-machine-profile.mjs:1365`)**:手破将 `prevGuestMachineId || profile.guest_machine_id` 优先级反转 -> 运行 `node --test test/unit/slot-machine-env.test.mjs` 复现失败(`20/21`,`ERR_ASSERTION: '01d94b76...' !== 'deadbeef...'`)-> 回退恢复 -> PASS(`21/21`)。
2. **F1(`src/lib/identity/official-fingerprint.mjs:45`)**:手破在 `reconcileFingerprint` 中将 `mp` 置为 `null` -> 运行 `node --test test/unit/official-fingerprint.test.mjs` 复现失败(`4/5`,`ERR_ASSERTION: '2222...2222' !== '1111...1111'`)-> 回退恢复 -> PASS(`5/5`)。
3. **K3(`docker/kin-kvm/guest/kin-slot-agent:759`)**:手破将 `_op_clear_slot_state` 短路返回 `{"cleared": []}` -> 运行 `python3 -m unittest discover -s docker/kin-kvm/guest -p test_kin_slot_agent.py -v` 复现失败(`11/12`,`AssertionError: False is not true : set()`)-> 回退恢复 -> PASS(`12/12 OK`)。
## 真实使用(Real use)
- 通过真实文件系统隔离目录演练 `kin-slot-agent` 清理会话态并保留凭据、`vm-registry.mjs` `persistVmTimezone` 原子替换并保持 `credentials.json`(`0o444` 封存)与 `kernel.json`(`0o640` 权限保留)。
- 在带 `kin-scheduler` 二进制的完整 `user-count-tokens` 与 `go-worker-client` 路径中验证 `safeguards[].classifier_context.prior_turn_context[].tool_use_ids` 映射及 SSE 分片 hex 尾部冲洗无截断。
## 未运行项(Not run)
- 未在本地启动完整 QEMU/KVM 虚拟机或连接真实上游 Claude / CRAG 内核进行端到端联调(依赖配套内核发版及宿主机 KVM 运行时环境)。
更新说明(Commit
|
2b9206f to
e9682cf
Compare
| def _remove_path_nofollow(self, target: Path, *, allow_dir: bool) -> bool: | ||
| try: | ||
| st = os.lstat(str(target)) | ||
| except FileNotFoundError: | ||
| return False | ||
| if stat.S_ISLNK(st.st_mode) or not stat.S_ISDIR(st.st_mode): | ||
| os.unlink(str(target)) | ||
| return True | ||
| if not allow_dir: | ||
| raise RpcError("unsafe_path", f"expected file, found directory: {target.name}") | ||
| # Restore write/exec bits on subdirectories (e.g. 0o555 sandbox .masks) before unlinking. | ||
| stack: list[Path] = [target] | ||
| dirs: list[Path] = [] | ||
| while stack: | ||
| cur = stack.pop() | ||
| try: | ||
| os.chmod(str(cur), 0o700) | ||
| except OSError: | ||
| pass | ||
| dirs.append(cur) | ||
| with os.scandir(str(cur)) as it: | ||
| for entry in it: | ||
| entry_path = Path(entry.path) | ||
| if entry.is_dir(follow_symlinks=False): | ||
| stack.append(entry_path) | ||
| else: | ||
| os.unlink(str(entry_path)) | ||
| for d in reversed(dirs): | ||
| os.rmdir(str(d)) | ||
| return True |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: HIGH
新增的 _remove_path_nofollow 只对叶子做了 lstat/unlink,目录遍历仍用字符串路径上的 chmod/scandir/rmdir,没有沿用同文件里 open_dir_nofollow 的逐级 O_NOFOLLOW dirfd。路径解析会跟随中间目录软链;在 lstat 判定为目录之后,槽内非特权进程还可以把该路径换成软链,让以 root 运行的 kin-slot-agent 删除目标目录中的文件。
Impact: 账号换绑、清凭证或粘性重置触发 clear_slot_state 时,槽内用户可把删除操作导向客户机系统目录或 bind-mount 进来的宿主路径,破坏该槽明确的 nofollow 写入隔离。
Reviewed by Cursor Security Reviewer for commit e9682cf. Configure here.
| clearSlotState: async (_vm, slotDir) => ({ | ||
| ok: true, | ||
| local: true, | ||
| cleared: clearLocalSlotStatePaths(slotDir), | ||
| }), |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: MEDIUM
集群 nodeHost.clearSlotState 只调用 clearLocalSlotStatePaths 清理控制面 vms/<id> 副本,不会删除节点上的 claude/credentials.json(0400 投影)、远端 .claude.json、continuations 或 telemetry。pushSlotCredentials 在本地文件已删时返回 local_missing 且不 unlink 远端。自定义 EROFS KVM 在存在 nodeId 时也不会挂上 clearCustomKvmSlotState。
Impact: 面板清凭证或换号后,节点 bind-mount 仍可能保留上一账号的 token 与会话日志,直到下一次成功推送覆盖。
Reviewed by Cursor Security Reviewer for commit e9682cf. Configure here.
评审结果(只读评审,评审时 head
|
…-M10 and Minors 1-3 - M1/M10: remove forbidden Node StickyRouter state I/O in panel-routes, import-commit, server, and scheduler-pools-routes; decouple global reset and wipeDisk from DELETE /api/panel/scheduler/sticky - M2/Minor 2: escape Windows memory directory targets in JSON streaming mode and preserve cross-chunk URL lookbehind in cwd-mapping SSE rewriter - M3: prevent double-derivation of x-claude-code-session-id on CLI/HTTP hops so header matches body metadata.user_id.session_id - M4: preserve legacy slots with existing device_id/Linux fingerprint on hot path, opt in newly created Claude slots, and rotate machine_profile + profile_generation + profile_reseed_nonce on traits recreate - M5: replace hardcoded pepper fallback with auto-generated 32-byte DB-persisted settings secret (slot_machine_profile_pepper) overridable by KIN_MACHINE_PROFILE_PEPPER and document in docs/TELEMETRY.md - M6: gate run/kernel.json machine_profile and 3-OS telemetry.identity (preserving legacy dmi_dir on crag-v2 <= 5.0.0) on slot_machine_profile_v1 or CRAG >= 5.0.2, and defer busy/unneeded account-swap kernel restarts - M7: gate one-way OS/Git persona text rewriting behind explicit opt-in (default OFF) and preserve # userEmail sentence wording - M8: persist vm.slot_epoch on account swap, credential/clear, reset-fingerprint, and traits recreate so restarts never roll back isolation epochs - M9: restore default crag_drop_foreign_thinking='off' - Minor 1/3: cycle-walk 24-char fallback tool IDs out of toolu_01<22-base62> namespace; flush slotSseRewriter idempotently in finally
评审整改与验收说明(Head
|
| 评审项 | 处置结果 | 关键改动与落点 |
|---|---|---|
M1(scheduler-m3-cutover 8/9→9/9) |
已修复 | 移除 panel-routes.mjs(reset/credential-clear)、import-commit.mjs、server.mjs 与 scheduler-pools-routes.mjs 中新增的 Node 侧 stickyRouter 状态读写,保留 Rust 调度器 deleteSticky 唯一真源;scheduler-m3-cutover 恢复 9/9 PASS。 |
M2(Windows input_json_delta 记忆目录 JSON 损坏) |
已修复 | src/lib/identity/cwd-mapping.mjs rewriteResponseInternal 统一对所有含 \ 的 Windows 目标前缀(含 callerMemoryBases)执行 toJsonEscapedWin,消除单反斜杠导致的 JSON.parse 报错。 |
M3(出站 x-claude-code-session-id 二次派生) |
已修复 | src/lib/transport/go-worker-client.mjs 对已由 identity.callerSessionId 或 body.metadata.user_id.session_id 单次派生的 x-claude-code-session-id 不再二次派生;handle-protocol.mjs 流式/组装路径同步透传 attemptMeta.sessionId 至 identity.callerSessionId,保证 header 与 body session_id 恒等。 |
M4(存量槽位懒迁移 & traits 重建轮换,作者已拍板) |
已实现 | slot-machine-profile.mjs 新增 isLegacySlotWithoutMachineProfile / shouldEnable3OsMachineProfile,热路径(handle-protocol.mjs / user-count-tokens.mjs)及 writeKernelConfig / oauth-credentials.mjs 绝不懒覆盖存量槽位既有的 device_id 与 Linux 指纹;新创建的 Claude 槽位(panel-routes.mjs POST /api/panel/vms/create)默认标记 machine_profile_opt_in: true;vm-recreate.mjs traits 模式递增 profile_generation + 生成新 profile_reseed_nonce 并轮换 machine_profile,即使重绑同一账号也派生全新机器画像。 |
M5(KIN_MACHINE_PROFILE_PEPPER 自动生成并持久化,作者已拍板) |
已实现 | 移除源码公开常量 DEFAULT_MACHINE_PROFILE_PEPPER;复用 panel-2fa.mjs 同款 SettingsRepo 模式(slot_machine_profile_pepper),未配置环境变量时自动生成 32 字节随机 hex 写入 DB settings 表,重启持久、不同安装互异;支持 KIN_MACHINE_PROFILE_PEPPER 环境变量覆盖(多实例共享),已补充文档至 docs/TELEMETRY.md。 |
M6(crag-v2 <= 5.0.0 能力门控 & 忙核重启保护) |
已修复 | slot-engine.mjs 新增 supportsSlotMachineProfileKernel(门控条件:slot_machine_profile_v1 能力或 CRAG 版本 >= 5.0.2);rust-kernel-supervisor.mjs(writeKernelConfig)与 oauth-credentials.mjs / import-commit.mjs 对旧内核(<= 5.0.0)保留 telemetry.dmi_dir 且省略 machine_profile 与新 telemetry.identity 键;import-commit.mjs 换号重启改为检查能力/配置变更与在途请求,内核繁忙时通过 requestKernelReloadWhenIdle 延后至空闲重启。 |
| M7(OS/Git 人设单向改写默认关闭,作者已拍板) | 已实现 | cwd-mapping.mjs(Platform:/Shell:/OS Version:/Timezone:/Locale:)与 git-persona.mjs(# userEmail/Git user:/Author:/Commit:/Co-Authored-By:/user.name=/user.email=)单向改写默认 OFF,仅在显式开启 KIN_SLOT_PERSONA_REWRITE=1 / routing.slot_persona_rewrite: true / vm.machine_profile.persona_rewrite: true 时生效;同时修复 # userEmail 改写正则,保留 "The user's email address is <email>" 句式。核心可逆隔离(CWD 路径、toolu ID、session ID、Git commit SHA)默认持续生效。 |
M8(slot_epoch 持久化,作者已拍板) |
已实现 | 换号(import-commit.mjs)、credential/clear、reset-fingerprint 与 traits 重建(vm-recreate.mjs)递增并持久化 vm.slot_epoch 至 vm.json,getSlotSessionEpoch 融合 Math.max(persistedVmEpoch, inMemoryVmEpoch),控制面重启不回滚换号隔离 epoch;单会话粘性清除继续走进程内 session epoch。 |
M9(crag_drop_foreign_thinking 默认值回退) |
已修复 | handle-protocol.mjs 恢复 crag_drop_foreign_thinking 默认 'off',移除本次 PR 夹带的默认值翻转与临时兜底函数。 |
M10(解耦 DELETE /api/panel/scheduler/sticky 高破坏联动) |
已修复 | scheduler-pools-routes.mjs 删除粘性时移除 resetSlotSessionState({ all: true }) 及 triggerRustKernelSlotReset(..., { wipeDisk }),仅当指定单个 session_id 时清理该会话内存态,不再触发全局重置或内核擦盘。 |
| M11(验证覆盖) | 已补齐 | 补全 M2/M3/M4/M5/M6/M7/M8/M10 及 Minor 1–2 单测,并完整验证 scheduler-m3-cutover、12 个关联单测文件、crs-persona/system-prompt-spec、test:ci(13/13)及 KVM guest Python 单测(12/12)。 |
| Minor 1(24 字符回退 tool ID 命名空间冲突) | 已修复 | tool-id-mapping.mjs 对 24 字符偶数回退载荷实施 FPE cycle-walking,避开 toolu_01<22-base62> 标准形命名空间,对评审反例 toolu_7bYRu8kffDafjxXUZoyzPPQF 及全量样本保证 100% 双射无冲突。 |
| Minor 2(SSE 分块边界 URL 保护) | 已修复 | cwd-mapping.mjs createSseStreamRewriter 维护 16 字符跨块回看尾巴(textPrevTail / jsonPrevTail)并透传 isUrlPrefixAt,https://example.com | /Users/<virtualHome>/x 跨块切分不再误改写。 |
| Minor 3(流式异常尾巴刷新) | 已修复 | handle-protocol.mjs 将 slotSseRewriter.flush() 收口为幂等 flushSlotSseTail(),同时在正常流结束前及 finally 块中执行(响应流仍可写时),防止异常中断丢失缓冲尾巴。 |
| Minor 4–7 | 已知/已记录 | Minor 7 文档已补齐至 docs/TELEMETRY.md(KIN_MACHINE_PROFILE_PEPPER、能力门控、存量槽位策略与 KIN_SLOT_PERSONA_REWRITE);Minor 4(远端 clearSlotState 本地副本语义)、Minor 5(非 git 语境裸 SHA 隔离范围)、Minor 6(滚动升级瞬时 continuation)留作后续小单跟进,不阻塞本次合入。 |
2. 验证命令与实测结果(全部在 WSL 实跑,零跳过)
- 代码格式与语法检查:
npx biome check <31 modified .mjs files>→ 31 files checked, 0 errors/warningsfind src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check→ PASSgit merge-tree --write-tree origin/dev HEAD→ 无冲突(tree9e2f36af435d5b5087e1c28be76b0cf38dbb2b6c)
- 调度器 M3 回归门禁(
KIN_SCHEDULER_BIN=/tmp/kin-sched-target/release/kin-scheduler):node --test test/unit/scheduler-m3-cutover.test.mjs→ 9/9 PASS(含 Acceptance fix(kernel): emit message_stop when wrap JobDone skips it #8 静态检查全绿)
- PR feat(identity,protocol): bind 3-OS slot machine profile and 4-module isolation #2472 关联单测(12 文件 + 2 补充文件):
slot-machine-env(30/30)、go-worker-client、rust-kernel-supervisor、scheduler-m1b-pools-api、oauth-credentials、agent-summary-routing、issued-tool-replay、vm-recreate、panel-public-boot、guest-identity、official-fingerprint、crs-headers→ 241/241 PASScrs-persona+system-prompt-spec→ 93/93 PASS
- CI 门禁套件:
npm run test:ci→ 13/13 isolated test files PASS
- KVM Guest Agent 单测:
python3 -m unittest -v docker/kin-kvm/guest/test_kin_slot_agent.py→ 12/12 PASS
3. 手动破坏性验证(Broken-by-Hand Evidence)
- M1:临时在
src/lib/admin/panel-routes.mjs插回stickyRouter?.unbindByAccount?.(...)→ 运行scheduler-m3-cutover.test.mjsAcceptance fix(kernel): emit message_stop when wrap JobDone skips it #8 立即失败(AssertionError: Forbidden StickyRouter state call in src/lib/admin/panel-routes.mjs,exit=1);还原后 9/9 PASS。 - M2:临时将
src/lib/identity/cwd-mapping.mjsJSON 规则匹配退回仅rule.target === st.callerCwd→ 运行slot-machine-env.test.mjsM2 用例精确复现评审报错(SyntaxError: Bad escaped character in JSON at position 17 (line 1 column 18),exit=1);还原后 3 种虚拟 OS 全部 PASS。 - M3:临时禁用
src/lib/transport/go-worker-client.mjs的identitySession / bodySession防重派生判断 → 运行go-worker-client.test.mjsM3 用例立即失败(AssertionError: CLI hop x-claude-code-session-id must NOT be double-derived,exit=1);还原后 PASS。
4. 未覆盖边界与风险说明
- 真实闭源 CRAG v2 内核(
<= 5.0.0旧核与>= 5.0.2新核)线上实跑、真实 Anthropic 上游联调与真机 KVM/dev/kvm集成测试不在本次离线单测覆盖范围内;能力门控与credentials.json/kernel.json合同已通过 mock manifest / health 单测闭环验证。 CHANGELOG.md未修改(遵守发版规范)。
5. 回滚方式
- 本次所有评审整改收敛为单个原子提交
8e4056ad2dc4421a3b3a90a6cf3bab3d691ab530(或整 PR 回滚git revert -m 1 <merge_sha>),不涉及数据库 schema 破坏性迁移;settings['slot_machine_profile_pepper']与vm.slot_epoch/profile_generation均为向后兼容增量字段,回滚无副作用。
| function clearLocalSlotStatePaths(slotDir) { | ||
| if (!slotDir) return [] | ||
| const targets = [ | ||
| ['credentials', path.join(slotDir, 'cli-home', '.claude', 'credentials.json')], | ||
| ['credentials_alias', path.join(slotDir, 'cli-home', '.claude', '.credentials.json')], | ||
| ['claude_profile', path.join(slotDir, 'cli-home', '.claude', '.claude.json')], | ||
| ['home_claude_profile', path.join(slotDir, 'cli-home', '.claude.json')], | ||
| ['crag_v3_continuations', path.join(slotDir, 'cli-home', '.claude', 'crag-v3-continuations')], | ||
| ['telemetry', path.join(slotDir, 'cli-home', '.claude', 'telemetry')], | ||
| ['crag_sessions', path.join(slotDir, 'run', 'work', '.crag-sessions')], | ||
| ['telemetry_upload_log', path.join(slotDir, 'run', 'telemetry-upload.log')], | ||
| ] | ||
| const cleared = [] | ||
| for (const [label, target] of targets) { | ||
| try { | ||
| if (fs.lstatSync(target)) { | ||
| fs.rmSync(target, { recursive: true, force: true }) | ||
| cleared.push(label) | ||
| } | ||
| } catch {} | ||
| } | ||
| return cleared | ||
| } |
There was a problem hiding this comment.
🔒 Agentic Security Review
Severity: HIGH
新增的 clearLocalSlotStatePaths 用 path.join 后直接 lstatSync/rmSync(recursive)清理 cli-home/.claude/* 与 run/work/.crag-sessions,没有复用同 PR 里 assertSafeSlotCredentialPaths / wipeSlotSessionAndTelemetryState 的逐级 lstat(拒绝中间软链)。lstatSync 只不跟随叶子,会跟随中间目录。
Impact: 本地 Docker 槽把 cli-home 以可写方式 bind 到 guest home。槽内进程若把 .claude 或 run/work 换成指向其他槽位或宿主路径的软链,随后的清凭证 / 换号 / clearSlotState 会以网关进程身份删除或覆盖目标树上的 credentials.json、.claude.json 与会话目录。
Reviewed by Cursor Security Reviewer for commit 8e4056a. Configure here.




变更摘要
darwin/win32/linux物理设备的确定性画像派生,跳过初始化引导的槽位易缺少配置子目录.claude.json与稳定 64-hexdevice_id;凭证与内核配置未能以统一脱敏画像联合下发。slotEpoch、issuedTools、遥测残留与内核重置接口的联动清理。src/lib/identity/{slot-machine-profile,cwd-mapping,git-persona,tool-id-mapping}.mjs)及对应单测(test/unit/slot-machine-env.test.mjs):内嵌三平台物理硬件/SMBIOS/系统目录,以账号绑定 HMAC-SHA256 确定性派生machine_profile(toPublicSlotMachineProfile剥离全部私有种子与非 Linux 键;projectProfileToVmFingerprint保留既有容器账号username),提供 8 类路径语法双向映射与分块安全的 SSE 流式重写、8 轮平衡 Feistel Git SHA/persona 映射,以及可逆toolu_*置换与按账号/槽位/代次隔离的 RFC 4122 UUIDv4 会话 ID。oauth-credentials.mjs、rust-kernel-supervisor.mjs、remote-slot-files.mjs、slot-host.mjs、slot-seed.mjs、workstation-profile.mjs、panel-api.mjs、vm-registry.mjs、vm-identity.mjs)实现credentials.json+run/kernel.json脱敏画像联合下发、双路径.claude.json同步写入、Custom-EROFS KVMkernel_config推送,以及面板安全展示三平台硬件特征(不暴露密钥种子与邮箱)。handle-protocol.mjs、go-worker-client.mjs、issued-tool-replay.mjs、import-commit.mjs、rust-kernel-client.mjs、vm-recreate.mjs、panel-routes.mjs、scheduler-pools-routes.mjs、server.mjs)接入单跳深拷贝四模块正向/非流式/SSE 逆向流水线(保留空partial_json: ""帧、严禁触碰thinking/signature块、默认foreign_only跨槽签名剥离),并在换号、槽位重建、清凭证与删除调度粘性时联动清理残留、推进slotEpoch、清空issuedTools并按能力协商调用POST /internal/v1/slot/reset。deploy/payload.json钉选将在内核签名版本发布后单独跟进。本 PR 所有新增内核交互均通过slot_machine_profile_v1/crag_slot_reset_v1能力门控,完全向后兼容crag-v2 <= 5.0.0。验收记录(Run)
origin/devf19435276find src scripts -name '*.mjs' -print0 | xargs -0 -n1 node --check: PASS (exit 0)npx biome check <28 changed/added files>: PASS (Checked 28 files, 0 issues)KIN_SCHEDULER_BIN=<temp>/kin-scheduler npm run test:ci: PASS (13/13 isolated suites)node --test test/unit/slot-machine-env.test.mjs test/unit/oauth-credentials.test.mjs test/unit/go-worker-client.test.mjs test/unit/panel-public-boot.test.mjs test/unit/scheduler-m1b-pools-api.test.mjs test/unit/agent-summary-routing.test.mjs: PASS (158/158 tests, 0 fail)回退与手破验证(Broken by hand)
credentials.json中的machineProfile(src/lib/oauth/oauth-credentials.mjs) ->node --test test/unit/oauth-credentials.test.mjsFAIL(31 pass, 1 fail,TypeError: Cannot read properties of undefined (reading 'device_id')) -> 恢复后 PASS(32/32)mapToolUseIdForAccount原样透传(src/lib/identity/tool-id-mapping.mjs) ->node --test test/unit/slot-machine-env.test.mjsFAIL(13 pass, 2 fail,ERR_ASSERTION捕获未置换toolu_01...) -> 恢复后 PASS(15/15)cwd-mapping.mjsSSE 分块边界缓冲findSafeFlushCut(src/lib/identity/cwd-mapping.mjs) ->node --test test/unit/slot-machine-env.test.mjsFAIL(14 pass, 1 fail,1 字符分块流漏还原路径触发ERR_ASSERTION) -> 恢复后 PASS(15/15)真实使用(Real use)
kin-scheduler二进制跑通 13/13 CI 隔离套件及网关四模块单跳正向/分块 SSE 逆向、双路配置下发、换号与删粘性重置回归。deploy/payload.json进行单槽验收。未运行项(Not run)
npm run test:unit):本次仅运行 13/13test:ci隔离套件与全部直接关联回归套件(158 项测试)。web/):本 PR 未触碰前端文件。Note
High Risk
Touches credential clearing, fingerprint reset, scheduler sticky deletion, and kernel slot reset—identity and session state can change across many code paths. Legacy slot preservation depends on opt-in gates; misconfiguration could overwrite fingerprints or leave stale kernel/session state.
Overview
Introduces account-bound 3-OS machine profiles (
machine_profile) and wires them through slot lifecycle, credentials, telemetry headers, and the admin panel—while preserving legacy slots unless explicitly opted in.New isolation layers add deterministic rewriting for paths/CWD/memory slugs (
createCwdMapper), Git author lines and commit SHAs (createGitPersonaRewriter), andtoolu_*IDs plus per-slot session UUIDs. Persona text rewriting stays off by default (KIN_SLOT_PERSONA_REWRITE/ routing flags). Profile secrets use a DB- or env-backed HMAC pepper (KIN_MACHINE_PROFILE_PEPPER).Operational flows expand: KVM
kin-slot-agentcansync_fileclaude_profileandclear_slot_state; credential clear / fingerprint reset bumpslot_epoch, wipe session & telemetry artifacts, sync kernel/credentials, delete scheduler stickies, and notify the Rust kernel (POST /internal/v1/slot/resetwhen capable). New Claude slots default tomachine_profile_opt_in: true. Panel public VM details now fall back tomachine_profilewhen legacy fingerprint fields are absent.Reviewed by Cursor Bugbot for commit 8e4056a. Configure here.