safe_join on Windows uses posixpath

fixes #2033
closes #2059
This commit is contained in:
David Lord 2017-05-15 16:58:01 -07:00
parent 88120e9e9d
commit 2a65794306
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 26 additions and 21 deletions

View file

@ -638,18 +638,24 @@ def safe_join(directory, *pathnames):
:raises: :class:`~werkzeug.exceptions.NotFound` if one or more passed
paths fall out of its boundaries.
"""
parts = [directory]
for filename in pathnames:
if filename != '':
filename = posixpath.normpath(filename)
for sep in _os_alt_seps:
if sep in filename:
raise NotFound()
if os.path.isabs(filename) or \
filename == '..' or \
filename.startswith('../'):
if (
any(sep in filename for sep in _os_alt_seps)
or os.path.isabs(filename)
or filename == '..'
or filename.startswith('../')
):
raise NotFound()
directory = os.path.join(directory, filename)
return directory
parts.append(filename)
return posixpath.join(*parts)
def send_from_directory(directory, filename, **options):