Browse Source

Merge "trivial: Remove vendored 'is_safe_url' function"

tags/16.0.0.0b2
Zuul 1 week ago
parent
commit
3abaeda160
2 changed files with 6 additions and 23 deletions
  1. 0
    15
      openstack_auth/utils.py
  2. 6
    8
      openstack_auth/views.py

+ 0
- 15
openstack_auth/utils.py View File

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

+ 6
- 8
openstack_auth/views.py View File

@@ -41,11 +41,6 @@ from openstack_auth.forms import Login  # noqa:F401
41 41
 from openstack_auth import user as auth_user
42 42
 from openstack_auth import utils
43 43
 
44
-try:
45
-    is_safe_url = http.is_safe_url
46
-except AttributeError:
47
-    is_safe_url = utils.is_safe_url
48
-
49 44
 
50 45
 LOG = logging.getLogger(__name__)
51 46
 
@@ -241,7 +236,8 @@ def switch(request, tenant_id, redirect_field_name=auth.REDIRECT_FIELD_NAME):
241 236
     # Ensure the user-originating redirection url is safe.
242 237
     # Taken from django.contrib.auth.views.login()
243 238
     redirect_to = request.GET.get(redirect_field_name, '')
244
-    if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
239
+    if not http.is_safe_url(url=redirect_to,
240
+                            allowed_hosts=[request.get_host()]):
245 241
         redirect_to = settings.LOGIN_REDIRECT_URL
246 242
 
247 243
     if auth_ref:
@@ -275,7 +271,8 @@ def switch_region(request, region_name,
275 271
                   region_name, request.user.username)
276 272
 
277 273
     redirect_to = request.GET.get(redirect_field_name, '')
278
-    if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
274
+    if not http.is_safe_url(url=redirect_to,
275
+                            allowed_hosts=[request.get_host()]):
279 276
         redirect_to = settings.LOGIN_REDIRECT_URL
280 277
 
281 278
     response = shortcuts.redirect(redirect_to)
@@ -305,7 +302,8 @@ def switch_keystone_provider(request, keystone_provider=None,
305 302
         raise exceptions.KeystoneAuthException(msg)
306 303
 
307 304
     redirect_to = request.GET.get(redirect_field_name, '')
308
-    if not is_safe_url(url=redirect_to, allowed_hosts=[request.get_host()]):
305
+    if not http.is_safe_url(url=redirect_to,
306
+                            allowed_hosts=[request.get_host()]):
309 307
         redirect_to = settings.LOGIN_REDIRECT_URL
310 308
 
311 309
     unscoped_auth_ref = None

Loading…
Cancel
Save