feat(security): privacy hardening + data export (v0.2.1)

- CORS: default localhost-only origins (was *, allowed any webpage
  to read local health data cross-site); env override MI_FITNESS_CORS_ORIGINS
- Host header allowlist middleware on FastAPI and Flask (DNS-rebinding
  protection); auto-configured for non-loopback binds via CLI
- Move API key passTokens from SQLite plaintext to system keyring,
  with automatic migration on startup and cleanup for revoked keys
- Disable uvicorn access log by default (query params out of terminals)
- New GET /api/export: JSON/CSV export of local data (offline, Excel BOM)
- Add docs/PRIVACY.md: full data-flow audit, outbound endpoint inventory,
  threat model, self-verification steps
- 6 new tests (host allowlist, keyring roundtrip, CSV)
This commit is contained in:
binglua committed 2026-09-03 22:43:15 +08:00
1 parent 42c42b2c9e
commit a47a8470f8
10 files changed
+444 -13

No files matched your search

+9
View File
@@ -1,5 +1,14 @@
# Changelog
## 0.2.1(隐私加固)
- 数据安全审计文档 `docs/PRIVACY.md`:全部对外请求清单(仅小米域名)、本机数据存放表、威胁模型与自验方法
- CORS 收紧:默认仅允许本机来源(原来为 `*`,恶意网页可跨站读取本地健康数据);可用 `MI_FITNESS_CORS_ORIGINS` 覆盖
- Host 头白名单中间件(FastAPI + Flask 双侧):阻断 DNS 重绑定攻击;非回环绑定时 CLI 自动放行绑定地址,可用 `MI_FITNESS_ALLOWED_HOSTS` 覆盖
- API Key 的 passToken 迁出 SQLite 明文,改存系统 keyring(启动时自动迁移历史数据);吊销时同步清理
- `api` 命令默认关闭 uvicorn 访问日志(查询参数不再落入终端)
- 新增 `GET /api/export`:本地数据导出为 JSON/CSV(含 Excel BOM),纯离线操作
## 0.2.0
- 内置 Web 仪表盘(`mi-fitness-mcp web`,Flask):可视化测试全部 API 端点、Key 管理、扫码登录,内置反向代理(自动附加 X-API-Key/X-Admin-Key,上游耗时透传)