Windows: 企业 EDR(奇安信天擎)拦截 MoveFileExW 导致启动写 index.html 报 EXDEV,CLI 完全无法启动
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 70/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- node.js, typescript
- Domain
- cli
Research direction
Search the CLI source for the atomic write of index.html using renameSync/temp file. Insert the try/catch fallback to copyFileSync on EXDEV/EPERM as suggested. Verify by running the built-in web server start or a unit test for the file-write helper.
Written by the indexing model from the issue text.
Description
问题描述
在企业 EDR 环境(奇安信天擎)下,CLI 启动内置 web 服务时用"写临时文件 + 原子改名"生成 index.html,rename 被安全软件过滤驱动拦截并返回 EXDEV,CLI 直接失败退出,无法使用。
Failed to start server: EXDEV: cross-device link not permitted, rename
'C:\Users\Administrator\AppData\Local\kimi-code\web\2.3.1\win32-x64\<hash>\dist-web\index.html.<pid>.<ts>.tmp'
-> '...\dist-web\index.html'
根因分析(已通过系统调用级实验确证)
天擎过滤驱动按目标扩展名(.html/.txt/.docx/.xlsx/.pdf/.jpg/.bat/.ps1 等)拦截特定的改名 API,与目录位置无关(C/D 盘任意目录均复现):
| Win32 API | rename 目标为 .html 等 | rename 目标为 .js/.exe 等 |
|---|---|---|
MoveFileW(普通改名) |
正常 | 正常 |
MoveFileExW(libuv uv_fs_rename 使用) |
ERROR_NOT_SAME_DEVICE (winerr 17) | 正常 |
MoveFileWithProgressW |
ERROR_NOT_SAME_DEVICE | 正常 |
关键点:
- 该拦截不是跨设备问题(各层目录均无 reparse point,同卷内 rename),
EXDEV错误码有强误导性 - 同一环境下普通
MoveFile与"复制+删除"均正常,操作本身可行,仅因 libuv 选择了被拦截的 API - 天擎"信任区"只豁免病毒扫描,不豁免此拦截;Windows Defender 已被第三方接管
- 该模式(tmp+rename 原子写文档类文件)在 Node/npm 生态广泛存在,影响面不限于本 CLI
复现
// Node v24.21.0,装有奇安信天擎的 Windows 机器
const fs = require('fs');
fs.writeFileSync('a.tmp', 'x');
fs.renameSync('a.tmp', 'b.html'); // 抛 EXDEV: cross-device link not permitted
fs.renameSync('a.tmp', 'b.js'); // 正常
对照(ctypes 直调 API):MoveFileExW(src, dst, 0) 和 (src, dst, MOVEFILE_REPLACE_EXISTING) 对 .html 目标均返回 winerr=17;MoveFileW 正常。
建议修复
原子写流程在 rename 失败时增加降级(对正常环境零影响):
try {
fs.renameSync(tmp, target);
} catch (e) {
if (['EXDEV', 'EPERM', 'EBUSY', 'EACCES'].includes(e.code)) {
fs.copyFileSync(tmp, target); // copy 路径不受上述规则影响,已验证
fs.unlinkSync(tmp);
} else {
throw e;
}
}
环境信息
- OS:Windows 10 Pro x64(简体中文),C/D 盘均 NTFS,无符号链接
- kimi-code CLI:2.3.1
- 安全软件:奇安信天擎企业定制版(奇安信过滤驱动层拦截)
- 临时绕过手段均无:天擎策略集中管控,本地无可用的排除项;扩展名白名单/信任区只豁免扫描层
- Dominant language
- TypeScript
- Stars
- 7.9k
- Forks
- 1.3k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 96
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from MoonshotAI/kimi-code
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MoonshotAI/kimi-code#4398 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MoonshotAI/kimi-code#4395 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
MoonshotAI/kimi-code#4392 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MoonshotAI/kimi-code#4369 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
MoonshotAI/kimi-code#4368 ·
Maintainers usually reply within 1 day
All issues in MoonshotAI/kimi-code
Similar issues
-
freshness freshness:observed-only
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
thoroc/context-radar#282 ·
-
bug P2 rust
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
area: web
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
gabe-santana/arkdraw#25 ·
-
bug require-triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
expressjs/expressjs.com#2549 · 1 reaction ·
Maintainers usually reply within 1 day
-
bug good first issue hacktoberfest
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
codercops/discord-bot#101 · 1 comment ·
Maintainers usually reply within 1 day