diff --git a/apps/common/utils/common.py b/apps/common/utils/common.py index 572820c49..0000d35b4 100644 --- a/apps/common/utils/common.py +++ b/apps/common/utils/common.py @@ -12,7 +12,7 @@ import copy import ipaddress -UUID_PATTERN = re.compile(r'[0-9a-zA-Z\-]{36}') +UUID_PATTERN = re.compile(r'\w{8}(-\w{4}){3}-\w{12}') ipip_db = None diff --git a/apps/orgs/views.py b/apps/orgs/views.py index e7bf9fc62..757129a7f 100644 --- a/apps/orgs/views.py +++ b/apps/orgs/views.py @@ -4,6 +4,7 @@ from django.http import HttpResponseForbidden from django.views.generic import DetailView, View from .models import Organization +from common.utils import UUID_PATTERN class SwitchOrgView(DetailView): @@ -17,10 +18,11 @@ class SwitchOrgView(DetailView): request.session['oid'] = oid host = request.get_host() referer = request.META.get('HTTP_REFERER') - if referer.find(host) != -1: - return redirect(referer) - else: - return redirect('index') + if referer.find(host) == -1: + return redirect(reverse('index')) + if UUID_PATTERN.search(referer): + return redirect(reverse('index')) + return redirect(referer) class SwitchToAOrgView(View):