Skip to content
Myr

Extra safety for safe_join. Does not look exploitable but better safe than sorry. Fixes #501

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

authored by Armin Ronacher · committed by Armin Ronacher · parent f701f69 · Browse files · 2 files+9 added−1 removed
This commit

State

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

Diff stats

2 files+9 added−1 removed

  • other:+9 added−1 removed

2 files+9 added−1 removed

modified:flask/testsuite/regression.py+6 added
15 unmodified lines
16import flask17import threading18import unittest19from werkzeug.test import run_wsgi_app, create_environ20from werkzeug.exceptions import NotFound21from flask.testsuite import FlaskTestCase222324_gc_lock = threading.Lock()
54 unmodified lines
79 with self.assert_no_leak():80 for x in xrange(10):81 fire()8283 def test_safe_join_toplevel_pardir(self):84 from flask.helpers import safe_join85 with self.assert_raises(NotFound):86 safe_join('/foo', '..')878889def suite():90 suite = unittest.TestSuite()91 suite.addTest(unittest.makeSuite(MemoryTestCase))92 return suite
modified:flask/helpers.py+3 added-1 removed
602 unmodified lines
603 filename = posixpath.normpath(filename)604 for sep in _os_alt_seps:605 if sep in filename:606 raise NotFound()607 if os.path.isabs(filename) or filename.startswith('../'):607 if os.path.isabs(filename) or \608 filename == '..' or \609 filename.startswith('../'):610 raise NotFound()611 return os.path.join(directory, filename)612613
264 unmodified lines