Make sure that windows servers do not allow downloading arbitrary files
This commit is contained in:
parent
fb88d9d025
commit
ed70b42798
1 changed files with 11 additions and 1 deletions
|
|
@ -58,6 +58,13 @@ else:
|
|||
_tojson_filter = json.dumps
|
||||
|
||||
|
||||
# what separators does this operating system provide that are not a slash?
|
||||
# this is used by the send_from_directory function to ensure that nobody is
|
||||
# able to access files from outside the filesystem.
|
||||
_os_alt_seps = list(sep for sep in [os.path.sep, os.path.altsep]
|
||||
if sep not in (None, '/'))
|
||||
|
||||
|
||||
def _endpoint_from_view_func(view_func):
|
||||
"""Internal helper that returns the default endpoint for a given
|
||||
function. This always is the function name.
|
||||
|
|
@ -413,7 +420,10 @@ def send_from_directory(directory, filename, **options):
|
|||
forwarded to :func:`send_file`.
|
||||
"""
|
||||
filename = posixpath.normpath(filename)
|
||||
if filename.startswith(('/', '../')):
|
||||
for sep in _os_alt_seps:
|
||||
if sep in filename:
|
||||
raise NotFound()
|
||||
if os.path.isabs(filename) or filename.startswith('../'):
|
||||
raise NotFound()
|
||||
filename = os.path.join(directory, filename)
|
||||
if not os.path.isfile(filename):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue