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
Provenance
- Commit
f7c35bf- Tree
af8848a- Author
David Lord <davidism@gmail.com>- Committer
Markus Unterwaditzer <markus@unterwaditzer.net>- Parent
4ff84d5
3 files changed+33 added−21 removed
modified:flask/helpers.py+14 added-8 removed
617 unmodified lines618 :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 """622+623+ parts = [directory]624+625 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('../'):628+629+ 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 directory636 637+ parts.append(filename)638 639+ return posixpath.join(*parts)640+641+642 def 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 linesmodified:tests/test_helpers.py+12 added-13 removed
844 unmodified lines845 assert called == [42]846 847 848 class TestSafeJoin(object):849-849 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 lines872 # 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 )883 884 for args in failing:885 with pytest.raises(NotFound):1 unmodified linemodified:CHANGES+7 added
13 unmodified lines14 - Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()15 method returns compressed response by default, and pretty response in16 debug mode.17 18+Version 0.12.219+--------------20+21+Bugfix release22+23+- Fix a bug in `safe_join` on Windows.24+25 Version 0.12.126 --------------27 28 Bugfix release, released on March 31st 2017605 unmodified lines