mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-21 20:55:14 +00:00
chore: 清理冗余代码与配置,优化项目结构
1. 删除无用文件与废弃代码:移除locale枚举、element-plus插件、sse路由、api token模块等 2. 简化类型导入与依赖:移除大量未使用的类型导入,统一echarts导入方式 3. 优化配置与样式:调整gitignore、样式引入顺序,新增列表动画样式 4. 修复接口与模型:修正接口返回类型、查询参数配置,更新部门模型字段 5. 优化性能与体验:添加图片懒加载,优化加载逻辑与表格渲染 6. 调整环境配置:新增并更新开发/生产环境配置文件
This commit is contained in:
@@ -1,3 +1,22 @@
|
||||
"""
|
||||
认证控制器 — TODO: 限流粒度细化
|
||||
---------------------------------
|
||||
当前登录(/login)和 OAuth 端点(/oauth/*)共享应用的通用限流配置,
|
||||
缺少独立的、更严格的限流策略。建议为以下端点配置独立的 RateLimiter:
|
||||
|
||||
1. /auth/login — 密码登录
|
||||
- 建议: 按 IP + 用户名组合限流,如 5次/分钟/IP + 10次/15分钟/用户
|
||||
- 原因: 暴力破解防护
|
||||
|
||||
2. /auth/oauth/* — 第三方 OAuth 登录/回调
|
||||
- 建议: 按 IP 限流,如 10次/分钟/IP
|
||||
- 原因: OAuth 流程可能触发多次重定向,频率稍高于登录
|
||||
|
||||
3. /auth/captcha/* — 验证码获取/校验
|
||||
- 建议: 按 IP 限流,如 3次/分钟/IP
|
||||
- 原因: 防止验证码遍历
|
||||
"""
|
||||
|
||||
import json
|
||||
import secrets
|
||||
from typing import Annotated
|
||||
|
||||
@@ -36,6 +36,12 @@ STATE_PREFIX = "oauth_state:"
|
||||
|
||||
def _callback_url(request: Request, provider: OAuthProvider) -> str:
|
||||
root = str(request.base_url).rstrip("/")
|
||||
# 域名白名单校验:防止 Host 头注入攻击重定向到恶意域名
|
||||
allowed_hosts = settings.OAUTH_ALLOWED_HOSTS
|
||||
if allowed_hosts and allowed_hosts != ["*"]:
|
||||
host = request.url.hostname
|
||||
if host is None or not any(host == allowed_host or host.endswith("." + allowed_host) for allowed_host in allowed_hosts):
|
||||
raise CustomException(msg="非法的 OAuth 回调域名")
|
||||
return f"{root}/system/auth/oauth/{provider}/callback"
|
||||
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ class LoginService:
|
||||
)
|
||||
|
||||
auth = AuthSchema()
|
||||
user = await UserCRUD(auth, db).get(username=login_form.username)
|
||||
user = await UserCRUD(auth, db).get(username=login_form.username, preload=["roles", "roles.menus"])
|
||||
|
||||
if not user:
|
||||
await _write_login_log(
|
||||
|
||||
Reference in New Issue
Block a user