fix(BIZ-109): 撤回 v2 临时白名单(BIZ-110 前端鉴权已就绪,恢复严格鉴权)
- 删除 AUTH_BYPASS_GET_PREFIXES / AUTH_BYPASS_POST_EXACT 配置项
- 删除 _is_bypass() 函数
- require_auth 中间件恢复严格鉴权逻辑(依赖 Bearer token)
- 前端 BIZ-110 commit dcc7339 已完成 localStorage + login 浮层 + Bearer 注入
- 回滚保险:app.py.bak.biz110.revoked.20260902(本地保留,未入库)
Refs: BIZ-109, BIZ-110
Op: opengineer @ 2026-09-02 17:50 GMT+8
This commit is contained in:
@@ -303,52 +303,15 @@ def find_draw_by_gen_time(gen_time):
|
|||||||
return None, 'error'
|
return None, 'error'
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# 认证装饰器(可选)
|
# 认证装饰器(严格鉴权 — BIZ-110 闭环后恢复)
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# BIZ-109 临时放行白名单 v2(v1 修复不彻底,用户验收仍报错,升级白名单)
|
# 2026-09-02 by 严维序 (opengineer)
|
||||||
#
|
# BIZ-110 前端鉴权适配完成后,撤回 BIZ-109 临时白名单(AUTH_BYPASS_* / _is_bypass)。
|
||||||
# 原因:BIZ-108 commit 31cabbe 启用 auth_enabled=True,但 index.html 前端
|
# index.html 前端 api() 函数已自动注入 'Authorization: Bearer <token>',
|
||||||
# api() 函数 (L944) 未注入 Authorization header。v1 白名单只覆盖
|
# 401 时清 localStorage + 跳登录页,鉴权闭环恢复。
|
||||||
# /api/records 和 /api/history 两个根路径,遗漏了子路径接口和
|
|
||||||
# /api/statistics、/api/generate,导致刘总验收仍报「未授权访问」。
|
|
||||||
#
|
|
||||||
# 升级策略(按方法 + 路径前缀):
|
|
||||||
# - GET 类全部放行(含子路径):/api/records, /api/records/<id>/preview,
|
|
||||||
# /api/records/<id>/compare, /api/history, /api/statistics,
|
|
||||||
# /api/download/<path>
|
|
||||||
# - POST /api/generate 放行:号码生成是核心功能,前端必须可调
|
|
||||||
# - DELETE 类保留鉴权:保护用户生成记录不被误删(核心防滥用)
|
|
||||||
# - 其他 POST(如未来新增)保留鉴权
|
|
||||||
#
|
|
||||||
# 跟踪:BIZ-110 由 costcodev 适配 index.html 前端后撤白名单,恢复完整鉴权。
|
|
||||||
# 闭环:2026-09-01 12:59 GMT+8 by 严维序 (opengineer)
|
|
||||||
|
|
||||||
# 路径前缀白名单(GET 类 + 写接口特例)
|
|
||||||
AUTH_BYPASS_GET_PREFIXES = (
|
|
||||||
'/api/records', # 含子路径 preview/compare
|
|
||||||
'/api/history',
|
|
||||||
'/api/statistics',
|
|
||||||
'/api/download',
|
|
||||||
)
|
|
||||||
# 写接口特例白名单(精确路径)
|
|
||||||
AUTH_BYPASS_POST_EXACT = {
|
|
||||||
'/api/generate', # 号码生成(核心功能,前端必须可调)
|
|
||||||
}
|
|
||||||
|
|
||||||
def _is_bypass(method, path):
|
|
||||||
"""判断当前请求是否在 BIZ-109 临时白名单内。"""
|
|
||||||
if method == 'GET':
|
|
||||||
return any(path.startswith(p) for p in AUTH_BYPASS_GET_PREFIXES)
|
|
||||||
if method == 'POST':
|
|
||||||
return path in AUTH_BYPASS_POST_EXACT
|
|
||||||
return False
|
|
||||||
|
|
||||||
def require_auth(f):
|
def require_auth(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
# BIZ-109 应急:白名单内请求临时放行
|
|
||||||
if _is_bypass(request.method, request.path):
|
|
||||||
return f(*args, **kwargs)
|
|
||||||
if CONFIG['auth_enabled']:
|
if CONFIG['auth_enabled']:
|
||||||
token = request.headers.get('Authorization', '').replace('Bearer ', '')
|
token = request.headers.get('Authorization', '').replace('Bearer ', '')
|
||||||
if token != CONFIG['api_token']:
|
if token != CONFIG['api_token']:
|
||||||
|
|||||||
Reference in New Issue
Block a user