feat(hermes-server): add Hermes Server with ce-code-review security fixes
实现独立的 Hermes Server 程序,部署在 Hermes 服务器上接收 EternalAI 同步请求。
主要功能:
- 接收 EternalAI 同步请求(POST /api/sync),验证 sync_token (JWT HS256)
- 回调 EternalAI 拉取 SOUL.md 和 config.yaml 文件
- 创建 profile(文件系统存储,无需数据库)
- 生成二维码绑定链接(PNG)
- 提供绑定页面和绑定 API(POST /api/bind/:profileId)
- 提供 profile 管理 API(列表/详情/删除/文件下载)
- 健康检查端点
ce-code-review 安全修复(2 P0, 8 P1, 10 P2, 12 P3):
- P0: SSRF 防护 — 使用 ETERNALAI_BASE_URL 环境变量,不信任请求体中的 filePullBaseUrl
- P0: profileId 路径穿越防护 — 正则校验 /^hermes_[a-f0-9]{24}$/
- P1: 原子文件写入(临时目录 + rename)
- P1: 绑定竞态条件修复(原子检查 alreadyBound)
- P1: jti 重放保护(内存 Map + 5 分钟 TTL)
- P1: 幂等去重(findByRoleId,重复同步先删后建)
- P1: 生产环境 fail-fast(HERMES_ADMIN_TOKEN 未设置时抛错)
- P1: 恒定时间比较 admin token(crypto.timingSafeEqual)
- P1: trust proxy 修复(仅 loopback)
- P1: IP 白名单使用 socket.remoteAddress
- P2: CORS 来源限制(ALLOWED_ORIGINS)
- P2: body 大小限制(1MB)
- P2: configYaml 非空校验
- P2: QR 码生成顺序(先创建 profile 再生成二维码)
- P2: 输入校验(profileName 长度限制)
- P2: listProfiles 容错
- P2: 健康检查不泄露 syncSecretConfigured
- P2: SOUL.md/config.yaml 本机访问限制
- P2: 绑定页面 try/catch
- P2: req.body null check
- P3: JWT 算法限制(仅 HS256)
- P3: 错误类型区分(504/502/500)
- P3: Content-Type 修复(text/markdown, text/yaml)
- P3: 404 状态码修复
- P3: form action 转义(encodeURIComponent)
- P3: deploy.sh 路径修复 + package-lock.json + npm ci
测试:20 个集成测试全部通过(端到端验证同步、二维码、绑定、写保护等)