VYPR
Moderate severityNVD Advisory· Published Oct 4, 2013· Updated Apr 29, 2026

CVE-2013-6044

CVE-2013-6044

Description

The is_safe_url function in utils/http.py in Django 1.4.x before 1.4.6, 1.5.x before 1.5.2, and 1.6 before beta 2 treats a URL's scheme as safe even if it is not HTTP or HTTPS, which might introduce cross-site scripting (XSS) or other vulnerabilities into Django applications that use this function, as demonstrated by "the login view in django.contrib.auth.views" and the javascript: scheme.

Affected packages

Versions sourced from the GitHub Security Advisory.

PackageAffected versionsPatched versions
DjangoPyPI
>= 1.4, < 1.4.61.4.6
DjangoPyPI
>= 1.5, < 1.5.21.5.2

Affected products

8
  • cpe:2.3:a:djangoproject:django:1.4:*:*:*:*:*:*:*+ 7 more
    • cpe:2.3:a:djangoproject:django:1.4:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.4.1:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.4.2:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.4.4:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.4.5:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.5:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.5.1:*:*:*:*:*:*:*
    • cpe:2.3:a:djangoproject:django:1.6:beta1:*:*:*:*:*:*

Patches

3
ae3535169af8

Fixed is_safe_url() to reject URLs that use a scheme other than HTTP/S.

https://github.com/django/djangoJacob Kaplan-MossAug 13, 2013via ghsa
2 files changed · +10 5
  • django/contrib/auth/tests/test_views.py+6 2 modified
    @@ -446,7 +446,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
     
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': login_url,
    @@ -467,6 +468,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    @@ -661,7 +663,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': logout_url,
                     'next': REDIRECT_FIELD_NAME,
    @@ -680,6 +683,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    
  • django/utils/http.py+4 3 modified
    @@ -252,11 +252,12 @@ def same_origin(url1, url2):
     def is_safe_url(url, host=None):
         """
         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.
         """
         if not url:
             return False
    -    netloc = urllib_parse.urlparse(url)[1]
    -    return not netloc or netloc == host
    +    url_info = urllib_parse.urlparse(url)
    +    return (not url_info.netloc or url_info.netloc == host) and \
    +        (not url_info.scheme or url_info.scheme in ['http', 'https'])
    
1a274ccd6bc1

Fixed is_safe_url() to reject URLs that use a scheme other than HTTP/S.

https://github.com/django/djangoJacob Kaplan-MossAug 13, 2013via ghsa
2 files changed · +10 5
  • django/contrib/auth/tests/views.py+6 2 modified
    @@ -328,7 +328,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
     
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': login_url,
    @@ -349,6 +350,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    @@ -522,7 +524,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': logout_url,
                     'next': REDIRECT_FIELD_NAME,
    @@ -541,6 +544,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    
  • django/utils/http.py+4 3 modified
    @@ -231,11 +231,12 @@ def same_origin(url1, url2):
     def is_safe_url(url, host=None):
         """
         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.
         """
         if not url:
             return False
    -    netloc = urllib_parse.urlparse(url)[1]
    -    return not netloc or netloc == host
    +    url_info = urllib_parse.urlparse(url)
    +    return (not url_info.netloc or url_info.netloc == host) and \
    +        (not url_info.scheme or url_info.scheme in ['http', 'https'])
    
ec67af0bd609

Fixed is_safe_url() to reject URLs that use a scheme other than HTTP/S.

https://github.com/django/djangoJacob Kaplan-MossAug 13, 2013via ghsa
2 files changed · +10 5
  • django/contrib/auth/tests/views.py+6 2 modified
    @@ -309,7 +309,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
     
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': login_url,
    @@ -330,6 +331,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    @@ -467,7 +469,8 @@ def test_security_check(self, password='password'):
             for bad_url in ('http://example.com',
                             'https://example.com',
                             'ftp://exampel.com',
    -                        '//example.com'):
    +                        '//example.com',
    +                        'javascript:alert("XSS")'):
                 nasty_url = '%(url)s?%(next)s=%(bad_url)s' % {
                     'url': logout_url,
                     'next': REDIRECT_FIELD_NAME,
    @@ -486,6 +489,7 @@ def test_security_check(self, password='password'):
                              '/view?param=ftp://exampel.com',
                              'view/?param=//example.com',
                              'https:///',
    +                         'HTTPS:///',
                              '//testserver/',
                              '/url%20with%20spaces/'):  # see ticket #12534
                 safe_url = '%(url)s?%(next)s=%(good_url)s' % {
    
  • django/utils/http.py+4 3 modified
    @@ -228,11 +228,12 @@ def same_origin(url1, url2):
     def is_safe_url(url, host=None):
         """
         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.
         """
         if not url:
             return False
    -    netloc = urlparse.urlparse(url)[1]
    -    return not netloc or netloc == host
    +    url_info = urlparse.urlparse(url)
    +    return (not url_info[1] or url_info[1] == host) and \
    +        (not url_info[0] or url_info[0] in ['http', 'https'])
    

Vulnerability mechanics

Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.

References

16

News mentions

0

No linked articles in our index yet.