feat: 重构控制面安全机制与分页规范
本次提交包含多项安全加固和体验优化: 1. 分离管理密钥与传输凭证,避免持 API Token 者伪造管理员票据 2. 钉钉回调地址增加白名单校验,防止开放重定向钓鱼 3. 初始管理员密码改为随机生成并日志记录,移除硬编码 123456 4. 新增登录防爆破计数表,支持 MySQL 多 worker 共享 5. 统一分页规范,新增 usePagedList composable 和 PagerBar 组件 6. 控制面 CORS 收敛为白名单,避免公网环境下任意站点跨域 7. 插件管理、凭证管理等列表接口支持分页和搜索 8. 强制初始密码修改,未改密前禁止使用管理功能 9. 定时任务触发被拒日志节流,避免授权失效时刷屏 10. 健康检查接口移除环境信息泄露,返回固定响应
This commit is contained in:
@@ -13,7 +13,7 @@ import json
|
||||
from fastapi import APIRouter, Header, HTTPException
|
||||
from pydantic import BaseModel
|
||||
|
||||
from controlplane.core.auth import _cloud_account, _resolve_login
|
||||
from controlplane.core.auth import _identity
|
||||
from controlplane.core.db import _db, _now
|
||||
|
||||
router = APIRouter()
|
||||
@@ -23,18 +23,13 @@ class _BackupIn(BaseModel):
|
||||
data: dict = {}
|
||||
|
||||
|
||||
def _identity(authorization: str = "", x_admin_token: str = "",
|
||||
x_api_token: str = "", x_admin_user: str = "") -> str:
|
||||
"""解析请求身份;无效则抛 401。"""
|
||||
account = _cloud_account(authorization)
|
||||
if not account:
|
||||
try:
|
||||
account = _resolve_login(x_admin_token, x_api_token, x_admin_user)
|
||||
except Exception:
|
||||
account = ""
|
||||
if not account:
|
||||
def _require_identity(authorization: str = "", x_admin_token: str = "",
|
||||
x_api_token: str = "", x_admin_user: str = "") -> str:
|
||||
"""统一身份解析(core.auth._identity),无效则抛 401。"""
|
||||
try:
|
||||
return _identity(authorization, x_admin_token, x_api_token, x_admin_user)
|
||||
except Exception:
|
||||
raise HTTPException(401, "登录态无效或已过期,请重新登录")
|
||||
return account
|
||||
|
||||
|
||||
@router.post("/api/schedules/backup")
|
||||
@@ -44,7 +39,7 @@ def sched_backup_save(b: _BackupIn,
|
||||
x_api_token: str = Header(default="", alias="X-API-Token"),
|
||||
x_admin_user: str = Header(default="", alias="X-Admin-User")) -> dict:
|
||||
"""覆盖保存某账号的定时任务全量配置(执行机变更后异步推送)。"""
|
||||
account = _identity(authorization, x_admin_token, x_api_token, x_admin_user)
|
||||
account = _require_identity(authorization, x_admin_token, x_api_token, x_admin_user)
|
||||
payload = b.data if isinstance(b.data, dict) else {}
|
||||
if not isinstance(payload.get("schedules"), list):
|
||||
raise HTTPException(400, "data.schedules 必须为数组")
|
||||
@@ -63,7 +58,7 @@ def sched_backup_load(authorization: str = Header(default="", alias="Authorizati
|
||||
x_api_token: str = Header(default="", alias="X-API-Token"),
|
||||
x_admin_user: str = Header(default="", alias="X-Admin-User")) -> dict:
|
||||
"""读取某账号备份的定时任务全量配置(执行机启动时合并恢复缺失任务)。"""
|
||||
account = _identity(authorization, x_admin_token, x_api_token, x_admin_user)
|
||||
account = _require_identity(authorization, x_admin_token, x_api_token, x_admin_user)
|
||||
with _db() as conn:
|
||||
row = conn.execute(
|
||||
"SELECT data FROM schedule_backups WHERE account = %s", (account,)).fetchone()
|
||||
|
||||
Reference in New Issue
Block a user