fix: Failed to switch languages

pull/15788/head
wangruidong 2025-07-29 16:34:20 +08:00 committed by 老广
parent 6b5d5c15ae
commit f3d9f4c446
1 changed files with 4 additions and 3 deletions

View File

@ -14,6 +14,7 @@ from django.shortcuts import HttpResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.http import is_same_domain
from .utils import set_current_request from .utils import set_current_request
@ -162,9 +163,9 @@ class SafeRedirectMiddleware:
target_host = parsed.netloc target_host = parsed.netloc
if target_host in [*settings.ALLOWED_HOSTS]: if target_host in [*settings.ALLOWED_HOSTS]:
return response return response
origin = f"{request.scheme}://{request.get_host()}" origin = request.get_host()
target_origin = f"{parsed.scheme}://{target_host}" target_origin = target_host
if not target_origin.startswith(origin): if not is_same_domain(origin, target_origin):
safe_redirect_url = '%s?%s' % (reverse('redirect-confirm'), f'next={quote(location)}') safe_redirect_url = '%s?%s' % (reverse('redirect-confirm'), f'next={quote(location)}')
return redirect(safe_redirect_url) return redirect(safe_redirect_url)
return response return response