mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-24 04:50:30 +00:00
fix: Failed to switch languages
This commit is contained in:
@@ -14,7 +14,6 @@ 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
|
||||||
|
|
||||||
@@ -163,9 +162,16 @@ 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 = request.get_host()
|
target_host, target_port = self._split_host_port(parsed.netloc)
|
||||||
target_origin = target_host
|
origin_host, origin_port = self._split_host_port(request.get_host())
|
||||||
if not is_same_domain(origin, target_origin):
|
if target_host != origin_host:
|
||||||
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
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _split_host_port(netloc):
|
||||||
|
if ':' in netloc:
|
||||||
|
host, port = netloc.split(':', 1)
|
||||||
|
return host, port
|
||||||
|
return netloc, '80'
|
||||||
|
Reference in New Issue
Block a user