Merge "trivial: Remove vendored 'is_safe_url' function"

This commit is contained in:
Zuul 2019-09-11 06:14:00 +00:00 committed by Gerrit Code Review
commit 3abaeda160
2 changed files with 6 additions and 23 deletions

View File

@ -99,21 +99,6 @@ def is_token_valid(token, margin=None):
return expiration > timezone.now()
# From django.contrib.auth.views
# Added in Django 1.4.3, 1.5b2
# Vendored here for compatibility with old Django versions.
def is_safe_url(url, host=None):
"""Return ``True`` if the url is a safe redirection.
The safe redirection means that it doesn't point to a different host.
Always returns ``False`` on an empty url.
"""
if not url:
return False
netloc = urlparse.urlparse(url)[1]
return not netloc or netloc == host
# Helper for figuring out keystone version
# Implementation will change when API version discovery is available
def get_keystone_version():

View File

@ -41,11 +41,6 @@ from openstack_auth.forms import Login # noqa:F401
from openstack_auth import user as auth_user
from openstack_auth import utils
try:
is_safe_url = http.is_safe_url
except AttributeError:
is_safe_url = utils.is_safe_url
LOG = logging.getLogger(__name__)
@ -241,7 +236,8 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
# Ensure the user-originating redirection url is safe.
# Taken from django.contrib.auth.views.login()
redirect_to = request.GET.get(redirect_field_name, '')
if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
if not http.is_safe_url(url=redirect_to,
allowed_hosts=[request.get_host()]):
redirect_to = settings.LOGIN_REDIRECT_URL
if auth_ref:
@ -275,7 +271,8 @@ def switch_region(request, region_name,
region_name, request.user.username)
redirect_to = request.GET.get(redirect_field_name, '')
if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
if not http.is_safe_url(url=redirect_to,
allowed_hosts=[request.get_host()]):
redirect_to = settings.LOGIN_REDIRECT_URL
response = shortcuts.redirect(redirect_to)
@ -305,7 +302,8 @@ def switch_keystone_provider(request, keystone_provider=None,
raise exceptions.KeystoneAuthException(msg)
redirect_to = request.GET.get(redirect_field_name, '')
if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
if not http.is_safe_url(url=redirect_to,
allowed_hosts=[request.get_host()]):
redirect_to = settings.LOGIN_REDIRECT_URL
unscoped_auth_ref = None