安全修复:加固CSRF与凭证保护并修复越权风险
This commit is contained in:
5
app.py
5
app.py
@@ -212,11 +212,12 @@ def enforce_csrf_protection():
|
||||
return
|
||||
if request.path.startswith("/static/"):
|
||||
return
|
||||
# 登录相关路由豁免 CSRF 检查(登录本身就是建立 session 的过程)
|
||||
# 登录挑战相关路由豁免 CSRF(会话尚未建立前需要可用)
|
||||
csrf_exempt_paths = {
|
||||
"/yuyx/api/login",
|
||||
"/api/login",
|
||||
"/api/auth/login",
|
||||
"/api/generate_captcha",
|
||||
"/yuyx/api/passkeys/login/options",
|
||||
"/yuyx/api/passkeys/login/verify",
|
||||
"/api/passkeys/login/options",
|
||||
@@ -224,8 +225,6 @@ def enforce_csrf_protection():
|
||||
}
|
||||
if request.path in csrf_exempt_paths:
|
||||
return
|
||||
if not (current_user.is_authenticated or "admin_id" in session):
|
||||
return
|
||||
token = request.headers.get("X-CSRF-Token") or request.form.get("csrf_token")
|
||||
if not token or not validate_csrf_token(token):
|
||||
return jsonify({"error": "CSRF token missing or invalid"}), 403
|
||||
|
||||
Reference in New Issue
Block a user