summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-03-14 12:33:15 -0400
committerTim Graham <timograham@gmail.com>2017-03-28 12:57:34 -0400
commit4a6b945dffe8d10e7cec107d93e6efaebfbded29 (patch)
tree3c275040d98d894825e47d34278566a9cf9a14a7 /django
parent081c263dff2acbef4f9cf6c972052d45ec09fc66 (diff)
[1.8.x] Fixed CVE-2017-7234 -- Fixed open redirect vulnerability in views.static.serve().
This is a security fix.
Diffstat (limited to 'django')
-rw-r--r--django/views/static.py22
1 files changed, 4 insertions, 18 deletions
diff --git a/django/views/static.py b/django/views/static.py
index 9959b96236..9e4e916b57 100644
--- a/django/views/static.py
+++ b/django/views/static.py
@@ -12,9 +12,9 @@ import stat
from django.http import (
FileResponse, Http404, HttpResponse, HttpResponseNotModified,
- HttpResponseRedirect,
)
from django.template import Context, Engine, TemplateDoesNotExist, loader
+from django.utils._os import safe_join
from django.utils.http import http_date, parse_http_date
from django.utils.six.moves.urllib.parse import unquote
from django.utils.translation import ugettext as _, ugettext_lazy
@@ -36,25 +36,11 @@ def serve(request, path, document_root=None, show_indexes=False):
but if you'd like to override it, you can create a template called
``static/directory_index.html``.
"""
- path = posixpath.normpath(unquote(path))
- path = path.lstrip('/')
- newpath = ''
- for part in path.split('/'):
- if not part:
- # Strip empty path components.
- continue
- drive, part = os.path.splitdrive(part)
- head, part = os.path.split(part)
- if part in (os.curdir, os.pardir):
- # Strip '.' and '..' in path.
- continue
- newpath = os.path.join(newpath, part).replace('\\', '/')
- if newpath and path != newpath:
- return HttpResponseRedirect(newpath)
- fullpath = os.path.join(document_root, newpath)
+ path = posixpath.normpath(unquote(path)).lstrip('/')
+ fullpath = safe_join(document_root, path)
if os.path.isdir(fullpath):
if show_indexes:
- return directory_index(newpath, fullpath)
+ return directory_index(path, fullpath)
raise Http404(_("Directory indexes are not allowed here."))
if not os.path.exists(fullpath):
raise Http404(_('"%(path)s" does not exist') % {'path': fullpath})