fix(BIZ-109): 临时放行 GET 只读接口鉴权(应急修复)

- 根因:BIZ-108 commit 31cabbe0 启用 auth_enabled=True,但
  index.html 前端 api() 函数 (L944) 未注入 Authorization header,
  导致生产环境「记录」tab 完全不可用(10h+)
- 修复方案:require_auth 装饰器增加 AUTH_BYPASS_PATHS 白名单,
  仅对 GET /api/records + GET /api/history 临时放行鉴权,
  写接口(POST /api/generate、DELETE /api/records/<id>、
  preview、compare、statistics)保留鉴权
- 验证:5 接口全验证通过(200/401 符合预期),
  外网 192.168.1.99:8085 访问正常
- 跟踪:BIZ-110 由 costcodev 适配前端后移除白名单
- 备份:app.py.bak.biz109.20260901050002
- 闭环:2026-09-01 05:18 GMT+8 by 严维序 (opengineer)
This commit is contained in:
2026-09-01 06:00:18 +08:00
parent 31cabbe044
commit fccfd775a3
+11
View File
@@ -305,9 +305,20 @@ def find_draw_by_gen_time(gen_time):
# ============================================================
# 认证装饰器(可选)
# ============================================================
# BIZ-109 临时放行白名单:仅 GET 只读接口临时放行鉴权(应急修复)
# 原因:BIZ-108 启用 auth_enabled 后,index.html 前端未适配 token 注入,
# 导致「记录」tab 完全不可用。临时放行只读接口恢复业务,
# BIZ-110 跟踪 index.html 适配后恢复鉴权。
# 白名单接口:GET /api/records, GET /api/history
# 保留鉴权接口:所有 POST/DELETE/写接口
AUTH_BYPASS_PATHS = {'/api/records', '/api/history'}
def require_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
# BIZ-109 应急:GET 只读接口临时放行
if request.method == 'GET' and request.path in AUTH_BYPASS_PATHS:
return f(*args, **kwargs)
if CONFIG['auth_enabled']:
token = request.headers.get('Authorization', '').replace('Bearer ', '')
if token != CONFIG['api_token']: