Skip to content
Myr

safe_join on Windows uses posixpath

Before adoption: this commit came in with the history the project adopted, so no landing records it.

fixes #2033 closes #2059

authored by David Lord · committed by Markus Unterwaditzer · parent 4ff84d5 · Browse files · 3 files+33 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+33 added−21 removed

  • tests:+12 added−13 removed
  • other:+21 added−8 removed

3 files+33 added−21 removed

modified:flask/helpers.py+14 added-8 removed
617 unmodified lines
618 :param pathnames: the untrusted pathnames relative to that directory.619 :raises: :class:`~werkzeug.exceptions.NotFound` if one or more passed620 paths fall out of its boundaries.621 """622623 parts = [directory]624625 for filename in pathnames:626 if filename != '':627 filename = posixpath.normpath(filename)625 for sep in _os_alt_seps:626 if sep in filename:627 raise NotFound()628 if os.path.isabs(filename) or \629 filename == '..' or \630 filename.startswith('../'):628629 if (630 any(sep in filename for sep in _os_alt_seps)631 or os.path.isabs(filename)632 or filename == '..'633 or filename.startswith('../')634 ):635 raise NotFound()632 directory = os.path.join(directory, filename)633 return directory636637 parts.append(filename)638639 return posixpath.join(*parts)640641642def send_from_directory(directory, filename, **options):643 """Send a file from a given directory with :func:`send_file`. This644 is a secure way to quickly expose static files from an upload folder645 or something similar.
321 unmodified lines
modified:tests/test_helpers.py+12 added-13 removed
844 unmodified lines
845 assert called == [42]846847848class TestSafeJoin(object):849849 def test_safe_join(self):850 # Valid combinations of *args and expected joined paths.851 passing = (853 (('a/b/c', ), 'a/b/c'),854 (('/', 'a/', 'b/', 'c/', ), '/a/b/c'),855 (('a', 'b', 'c', ), 'a/b/c'),856 (('/a', 'b/c', ), '/a/b/c'),857 (('a/b', 'X/../c'), 'a/b/c', ),858 (('/a/b', 'c/X/..'), '/a/b/c', ),852 (('a/b/c',), 'a/b/c'),853 (('/', 'a/', 'b/', 'c/'), '/a/b/c'),854 (('a', 'b', 'c'), 'a/b/c'),855 (('/a', 'b/c'), '/a/b/c'),856 (('a/b', 'X/../c'), 'a/b/c'),857 (('/a/b', 'c/X/..'), '/a/b/c'),858 # If last path is '' add a slash860 (('/a/b/c', '', ), '/a/b/c/', ),859 (('/a/b/c', ''), '/a/b/c/'),860 # Preserve dot slash862 (('/a/b/c', './', ), '/a/b/c/.', ),863 (('a/b/c', 'X/..'), 'a/b/c/.', ),861 (('/a/b/c', './'), '/a/b/c/.'),862 (('a/b/c', 'X/..'), 'a/b/c/.'),863 # Base directory is always considered safe864 (('../', 'a/b/c'), '../a/b/c'),865 (('/..', ), '/..'),866 )
5 unmodified lines
872 # Should raise werkzeug.exceptions.NotFound on unsafe joins.873 failing = (874 # path.isabs and ``..'' checks875 ('/a', 'b', '/c'),877 ('/a', '../b/c', ),876 ('/a', '../b/c'),877 ('/a', '..', 'b/c'),878 # Boundaries violations after path normalization880 ('/a', 'b/../b/../../c', ),879 ('/a', 'b/../b/../../c'),880 ('/a', 'b', 'c/../..'),882 ('/a', 'b/../../c', ),881 ('/a', 'b/../../c'),882 )883884 for args in failing:885 with pytest.raises(NotFound):
1 unmodified line
modified:CHANGES+7 added
13 unmodified lines
14- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()15 method returns compressed response by default, and pretty response in16 debug mode.1718Version 0.12.219--------------2021Bugfix release2223- Fix a bug in `safe_join` on Windows.2425Version 0.12.126--------------2728Bugfix release, released on March 31st 2017
605 unmodified lines