Archived
feat(routes): 迁移账号/全局歌单端点 + 鉴权依赖测试
迁移路由(/api/v1/*,与 Flask 同端点逐字段对齐): - account/vip:admin/user 双路径 + 5 分钟缓存(降级结果 30s), VIP 探测单飞锁与 Flask 同源跨栈共享;未登录可访问(同 Flask) - global/playlists、global/playlist:管理员闸(require_admin,403 对齐) - web/deps.py 新增 require_admin;_resolve_user_cookies 支持可选用户(匿名审计保底) 测试:46/46(新增 10 项鉴权依赖:有效/管理员/封禁/禁用/顶号/伪造 Cookie、 401/403 闸);ruff All checks passed;pyright 0 errors。 契约奇偶校验:16 项全 OK(新增 account:vip、global:playlists/playlist、 非管理员 403);uvicorn 实跑双栈 account/vip 均 200、未授权歌单 403。
This commit is contained in:
1 parent
a2758aa0da
commit
6c3181341b
5 files changed
+287
-2
No files matched your search
@@ -243,7 +243,9 @@ def _global_music_u() -> str:
|
||||
return GLOBAL_MUSIC_U_CACHE['v']
|
||||
|
||||
|
||||
async def _resolve_user_cookies(data: dict[str, Any], user: SiteUser, request: Request) -> dict[str, str]:
|
||||
async def _resolve_user_cookies(
|
||||
data: dict[str, Any], user: 'SiteUser | None', request: Request
|
||||
) -> dict[str, str]:
|
||||
"""解析个人账号 Cookie(浏览器传入的 user_cookie,不落服务器)。
|
||||
|
||||
全局账号(cookie.txt)零个人身份权限:浏览器提交的 MUSIC_U 若与全局账号一致
|
||||
@@ -255,7 +257,8 @@ async def _resolve_user_cookies(data: dict[str, Any], user: SiteUser, request: R
|
||||
if mu and gmu and hmac.compare_digest(mu, gmu):
|
||||
try:
|
||||
import auth_system
|
||||
await asyncio.to_thread(auth_system.add_log, 'fail', user.username,
|
||||
await asyncio.to_thread(auth_system.add_log, 'fail',
|
||||
user.username if user else '匿名',
|
||||
ratelimit.client_ip(request), '全局账号冒用拦截',
|
||||
'浏览器提交的 MUSIC_U 与全局账号一致,已按未登录拒绝')
|
||||
except Exception:
|
||||
|
||||
Reference in new issue
Block a user