Files
Nexus/docs/changelog/2026-05-22-global-jwt-middleware.md
T
2026-07-08 22:31:31 +08:00

21 lines
839 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 全局 JWT 中间件(F2a-10 / F2d-02
**日期**: 2026-05-22
## 变更
- `server/api/auth_jwt.py`:新增 `JwtAuthMiddleware`,对所有 `/api/*` 请求在路由处理前校验 Bearer JWT;公开前缀见 `PUBLIC_PREFIXES`(含 `/api/install/``/api/auth/logout`)。
- `server/main.py`:在 `DbSessionMiddleware` 内层注册中间件(保证 `request.state.db` 可用)。
- `get_current_admin`:复用 `request.state.admin`,避免重复查库。
- 安装模式(无 `.env`)跳过 JWT 中间件,由 `InstallModeMiddleware` 返回 503。
## 纵深防御
路由层 `Depends(get_current_admin)` 保留;即使新路由漏挂 Depends,中间件仍会返回 401。
## 验证
```bash
pytest tests/test_step0_infrastructure.py::TestJWTAuth tests/test_nexus_v6.py::TestJWTAuth tests/test_security_unit.py -q
```