mirror of
https://wget.la/https://github.com/Wxw-Gu/WechatExplorer
synced 2026-08-17 11:37:06 +08:00
feat: 为本地 HTTP API 增加 Token 鉴权与安全加固
- 使用 Electron safeStorage 加密存储并自动初始化 API Token - 为 health 以外的接口增加 Bearer Token 鉴权 - 限制 CORS 仅允许可信本地 Origin - 增加鉴权、Token rotation、safeStorage 和手动验收测试
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# Local API Security
|
||||
|
||||
WechatExplorer 的安全模型是:本机回环地址 + 高熵 Bearer Token。
|
||||
|
||||
- Token 使用密码学安全随机源生成,并由 Electron safeStorage 加密保存。
|
||||
- 应用升级或首次启动时自动、幂等生成;应用重启后保持不变。
|
||||
- API Center 可以显示、复制或重新生成 Token。重新生成后旧 Token 立即失效。
|
||||
- `/api/v1/health` 公开且不返回聊天内容、数据库路径、Token 或 Provider 信息。
|
||||
- 其他 endpoint 缺少或使用错误 Token 时返回 `401 Unauthorized`。
|
||||
- CORS 仅允许精确的 localhost、127.0.0.1 和 ::1 HTTP Origin;无 Origin 的 curl、Node 和本地 Agent 请求正常工作。
|
||||
|
||||
本地 API 不应暴露到公网或不受信任网络。Bearer Token 提供本机 API 访问保护,但不是公网网关、用户账户系统或完整权限 Scope 系统。
|
||||
@@ -0,0 +1,16 @@
|
||||
# WechatExplorer Local HTTP API
|
||||
|
||||
WechatExplorer v2.1.9 默认在 `127.0.0.1:6131` 提供 Local HTTP API。
|
||||
|
||||
- `GET /api/v1/health` 无需鉴权。
|
||||
- 其他数据和 Agent endpoint 需要 `Authorization: Bearer <TOKEN>`。
|
||||
- Token 从 WechatExplorer → API Center → API Token 获取。
|
||||
- Token 不得放入 URL、仓库或共享配置。
|
||||
|
||||
```bash
|
||||
export WECHATEXPLORER_API_TOKEN="<YOUR_API_TOKEN>"
|
||||
curl -H "Authorization: Bearer $WECHATEXPLORER_API_TOKEN" \
|
||||
http://127.0.0.1:6131/api/v1/recent_chat
|
||||
```
|
||||
|
||||
完整 endpoint 与使用流程见 [Reader Skill](../skill/wechatexplorer-reader/SKILL.md),安全边界见 [API Security](./api-security.md)。
|
||||
@@ -0,0 +1,11 @@
|
||||
# Reader Skill Authentication
|
||||
|
||||
WechatExplorer Reader 是 Local HTTP API Skill,不是 MCP Server。
|
||||
|
||||
1. 打开 WechatExplorer → API Center。
|
||||
2. 确认 API 和数据库已就绪。
|
||||
3. 在 API Token 区域复制 Token。
|
||||
4. 将它保存到 Agent 自己的本地环境配置:`WECHATEXPLORER_API_TOKEN=<YOUR_API_TOKEN>`。
|
||||
5. 安装 Reader Skill,并让所有数据请求携带 `Authorization: Bearer $WECHATEXPLORER_API_TOKEN`。
|
||||
|
||||
Codex、Claude Code、OpenClaw 和其他 Agent 均使用相同的 HTTP Bearer Token 模型。WechatExplorer 不会自动把 Token 写入任何 Agent 配置。
|
||||
@@ -0,0 +1,11 @@
|
||||
# WechatExplorer v2.1.9 API Authentication
|
||||
|
||||
v2.1.9 为 Local HTTP API 增加 Bearer Token 鉴权。这是有意的 breaking change。
|
||||
|
||||
- v2.1.8:`GET /api/v1/contact` 可能直接返回数据。
|
||||
- v2.1.9:相同请求必须携带 `Authorization: Bearer <TOKEN>`,否则返回 `401`。
|
||||
- `GET /api/v1/health` 保持公开。
|
||||
- 老用户升级后会自动生成并安全保存 Token,不改变原有 apiEnabled、host 或 port 设置。
|
||||
- Token 可在 WechatExplorer → API Center 中显示、复制和重新生成。
|
||||
|
||||
Reader Skill 和本地 Agent 需要使用 `WECHATEXPLORER_API_TOKEN` 更新本机配置。
|
||||
Reference in New Issue
Block a user