fix: AI analysis history user isolation & password change Turnstile bypass

This commit is contained in:
TIANHE
2026-01-31 22:34:26 +08:00
parent d5e023a774
commit 70269c40c9
6 changed files with 108 additions and 24 deletions
+19 -4
View File
@@ -472,10 +472,25 @@ def send_verification_code():
if not email or not email_service.is_valid_email(email):
return jsonify({'code': 0, 'msg': 'Invalid email address', 'data': None}), 400
# Verify Turnstile
turnstile_ok, turnstile_msg = security.verify_turnstile(turnstile_token, ip_address)
if not turnstile_ok:
return jsonify({'code': 0, 'msg': turnstile_msg, 'data': None}), 400
# For change_password type with logged-in user, skip Turnstile verification
# because user already authenticated
skip_turnstile = False
if code_type == 'change_password':
# Try to get user_id from token (this route doesn't require login)
from app.utils.auth import verify_token
auth_header = request.headers.get('Authorization')
if auth_header:
parts = auth_header.split()
if len(parts) == 2 and parts[0].lower() == 'bearer':
payload = verify_token(parts[1])
if payload and payload.get('user_id'):
skip_turnstile = True
# Verify Turnstile (skip for authenticated change_password requests)
if not skip_turnstile:
turnstile_ok, turnstile_msg = security.verify_turnstile(turnstile_token, ip_address)
if not turnstile_ok:
return jsonify({'code': 0, 'msg': turnstile_msg, 'data': None}), 400
# Check rate limit
can_send, rate_msg = security.can_send_verification_code(email, ip_address)