Fixed is_safe_url() to reject URLs that use a scheme other than HTTP/S.
This is a security fix; disclosure to follow shortly.
This commit is contained in:
parent
b50be6857c
commit
ec67af0bd6
@ -309,7 +309,8 @@ class LoginTest(AuthViewsTestCase):
|
|||||||
for bad_url in ('http://example.com',
|
for bad_url in ('http://example.com',
|
||||||
'https://example.com',
|
'https://example.com',
|
||||||
'ftp://exampel.com',
|
'ftp://exampel.com',
|
||||||
'//example.com'):
|
'//example.com',
|
||||||
|
'javascript:alert("XSS")'):
|
||||||
|
|
||||||
nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
|
nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
|
||||||
'url': login_url,
|
'url': login_url,
|
||||||
@ -330,6 +331,7 @@ class LoginTest(AuthViewsTestCase):
|
|||||||
'/view?param=ftp://exampel.com',
|
'/view?param=ftp://exampel.com',
|
||||||
'view/?param=//example.com',
|
'view/?param=//example.com',
|
||||||
'https:///',
|
'https:///',
|
||||||
|
'HTTPS:///',
|
||||||
'//testserver/',
|
'//testserver/',
|
||||||
'/url%20with%20spaces/'): # see ticket #12534
|
'/url%20with%20spaces/'): # see ticket #12534
|
||||||
safe_url = '%(url)s?%(next)s=%(good_url)s' % {
|
safe_url = '%(url)s?%(next)s=%(good_url)s' % {
|
||||||
@ -467,7 +469,8 @@ class LogoutTest(AuthViewsTestCase):
|
|||||||
for bad_url in ('http://example.com',
|
for bad_url in ('http://example.com',
|
||||||
'https://example.com',
|
'https://example.com',
|
||||||
'ftp://exampel.com',
|
'ftp://exampel.com',
|
||||||
'//example.com'):
|
'//example.com',
|
||||||
|
'javascript:alert("XSS")'):
|
||||||
nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
|
nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
|
||||||
'url': logout_url,
|
'url': logout_url,
|
||||||
'next': REDIRECT_FIELD_NAME,
|
'next': REDIRECT_FIELD_NAME,
|
||||||
@ -486,6 +489,7 @@ class LogoutTest(AuthViewsTestCase):
|
|||||||
'/view?param=ftp://exampel.com',
|
'/view?param=ftp://exampel.com',
|
||||||
'view/?param=//example.com',
|
'view/?param=//example.com',
|
||||||
'https:///',
|
'https:///',
|
||||||
|
'HTTPS:///',
|
||||||
'//testserver/',
|
'//testserver/',
|
||||||
'/url%20with%20spaces/'): # see ticket #12534
|
'/url%20with%20spaces/'): # see ticket #12534
|
||||||
safe_url = '%(url)s?%(next)s=%(good_url)s' % {
|
safe_url = '%(url)s?%(next)s=%(good_url)s' % {
|
||||||
|
@ -228,11 +228,12 @@ else:
|
|||||||
def is_safe_url(url, host=None):
|
def is_safe_url(url, host=None):
|
||||||
"""
|
"""
|
||||||
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
|
Return ``True`` if the url is a safe redirection (i.e. it doesn't point to
|
||||||
a different host).
|
a different host and uses a safe scheme).
|
||||||
|
|
||||||
Always returns ``False`` on an empty url.
|
Always returns ``False`` on an empty url.
|
||||||
"""
|
"""
|
||||||
if not url:
|
if not url:
|
||||||
return False
|
return False
|
||||||
netloc = urlparse.urlparse(url)[1]
|
url_info = urlparse.urlparse(url)
|
||||||
return not netloc or netloc == host
|
return (not url_info[1] or url_info[1] == host) and \
|
||||||
|
(not url_info[0] or url_info[0] in ['http', 'https'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user