Skip to content

fix(security): block arbitrary file read and harden plugin hooks#903

Open
JinyuXiang-Mimo wants to merge 3 commits into
XiaomiMiMo:mainfrom
JinyuXiang-Mimo:security/analyze-file-read-vuln
Open

fix(security): block arbitrary file read and harden plugin hooks#903
JinyuXiang-Mimo wants to merge 3 commits into
XiaomiMiMo:mainfrom
JinyuXiang-Mimo:security/analyze-file-read-vuln

Conversation

@JinyuXiang-Mimo

Copy link
Copy Markdown
Collaborator

Summary

  • 修复 InstanceMiddlewaredirectory 参数注入导致的任意文件读取漏洞
  • 三层纵深防御:启动强制认证、目录合法性验证、无认证限制 cwd 子目录
  • 修复 macOS symlink 路径下 cwd 比对误拒
  • Plugin file hooks 增加 structuredClone rollback、5s timeout、circuit breaker(3 次失败后自动跳过)

攻击向量

GET /file/content?directory=/etc&path=passwd 绕过路径检查读取系统任意文件。
根因:middleware 盲目接受用户提供的 directory 作为项目根目录。

防御层

  1. Layer 1 — 非 loopback 启动必须设置 MIMOCODE_SERVER_PASSWORD(或 --no-auth
  2. Layer 2isValidProjectDirectory() 拒绝系统路径,要求项目标记文件
  3. Layer 3 — 无认证服务器限制 directory 在 cwd 子目录内
  4. Plugin hooks — 单 hook 粒度的快照回滚 + 超时 + 熔断

…ooks

File hooks (user-written .mimocode/hooks/) now get three layers of protection:
- structuredClone snapshot before execution, restored on error
- 5s timeout via Promise.race to prevent infinite hangs
- Circuit breaker that auto-skips hooks after 3 consecutive failures

Internal plugin hooks remain unguarded for performance.
…ction

The InstanceMiddleware accepts a `directory` query parameter that sets
the project root for the request. Attackers can pass `directory=/etc`
to read any system file (e.g. /etc/passwd, /etc/shadow) because
containsPath validates against the attacker-controlled directory.

Fix with 3 defense layers:
- Layer 1: Refuse to start on non-loopback without MIMOCODE_SERVER_PASSWORD
- Layer 2: Validate directory against system paths and require project markers
- Layer 3: Unauthenticated servers restrict directory to cwd subtree
Filesystem.resolve() uses realpathSync to canonicalize the directory
parameter, but the cwd comparison used raw process.cwd(). On macOS
where /tmp → /private/tmp (or any symlink'd project dir), this mismatch
causes false 403 rejections for legitimate requests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant