Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5f1ffb0

Browse files
committed
[1.9.x] Fixed CVE-2017-7234 -- Fixed open redirect vulnerability in views.static.serve().
This is a security fix.
1 parent cb87583 commit 5f1ffb0

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

django/views/static.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
from django.http import (
1414
FileResponse, Http404, HttpResponse, HttpResponseNotModified,
15-
HttpResponseRedirect,
1615
)
1716
from django.template import Context, Engine, TemplateDoesNotExist, loader
17+
from django.utils._os import safe_join
1818
from django.utils.http import http_date, parse_http_date
1919
from django.utils.six.moves.urllib.parse import unquote
2020
from django.utils.translation import ugettext as _, ugettext_lazy
@@ -36,25 +36,11 @@ def serve(request, path, document_root=None, show_indexes=False):
3636
but if you'd like to override it, you can create a template called
3737
``static/directory_index.html``.
3838
"""
39-
path = posixpath.normpath(unquote(path))
40-
path = path.lstrip('/')
41-
newpath = ''
42-
for part in path.split('/'):
43-
if not part:
44-
# Strip empty path components.
45-
continue
46-
drive, part = os.path.splitdrive(part)
47-
head, part = os.path.split(part)
48-
if part in (os.curdir, os.pardir):
49-
# Strip '.' and '..' in path.
50-
continue
51-
newpath = os.path.join(newpath, part).replace('\\', '/')
52-
if newpath and path != newpath:
53-
return HttpResponseRedirect(newpath)
54-
fullpath = os.path.join(document_root, newpath)
39+
path = posixpath.normpath(unquote(path)).lstrip('/')
40+
fullpath = safe_join(document_root, path)
5541
if os.path.isdir(fullpath):
5642
if show_indexes:
57-
return directory_index(newpath, fullpath)
43+
return directory_index(path, fullpath)
5844
raise Http404(_("Directory indexes are not allowed here."))
5945
if not os.path.exists(fullpath):
6046
raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})

docs/releases/1.8.18.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ Django 1.8.18 release notes
55
*April 4, 2017*
66

77
Django 1.8.18 fixes two security issues in 1.8.17.
8+
9+
CVE-2017-7234: Open redirect vulnerability in ``django.views.static.serve()``
10+
=============================================================================
11+
12+
A maliciously crafted URL to a Django site using the
13+
:func:`~django.views.static.serve` view could redirect to any other domain. The
14+
view no longer does any redirects as they don't provide any known, useful
15+
functionality.
16+
17+
Note, however, that this view has always carried a warning that it is not
18+
hardened for production use and should be used only as a development aid.

docs/releases/1.9.13.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ Django 1.9.13 release notes
77
Django 1.9.13 fixes two security issues and a bug in 1.9.12. This is the final
88
release of the 1.9.x series.
99

10+
CVE-2017-7234: Open redirect vulnerability in ``django.views.static.serve()``
11+
=============================================================================
12+
13+
A maliciously crafted URL to a Django site using the
14+
:func:`~django.views.static.serve` view could redirect to any other domain. The
15+
view no longer does any redirects as they don't provide any known, useful
16+
functionality.
17+
18+
Note, however, that this view has always carried a warning that it is not
19+
hardened for production use and should be used only as a development aid.
20+
1021
Bugfixes
1122
========
1223

0 commit comments

Comments
 (0)