diff options
| author | Florian Apolloner <florian@apolloner.eu> | 2021-12-17 21:07:50 +0100 |
|---|---|---|
| committer | Carlton Gibson <carlton.gibson@noumenal.es> | 2022-01-04 10:04:12 +0100 |
| commit | 6d343d01c57eb03ca1c6826318b652709e58a76e (patch) | |
| tree | 969ef783b8400a7459eaa9a5efc4a5bcc8244b1f /tests/file_storage | |
| parent | 761f449e0daf3de06b0132bd4d6dfcdeef578e26 (diff) | |
Fixed CVE-2021-45452 -- Fixed potential path traversal in storage subsystem.
Thanks to Dennis Brinkrolf for the report.
Diffstat (limited to 'tests/file_storage')
| -rw-r--r-- | tests/file_storage/test_generate_filename.py | 19 | ||||
| -rw-r--r-- | tests/file_storage/tests.py | 6 |
2 files changed, 19 insertions, 6 deletions
diff --git a/tests/file_storage/test_generate_filename.py b/tests/file_storage/test_generate_filename.py index 66551c495b..78fd064732 100644 --- a/tests/file_storage/test_generate_filename.py +++ b/tests/file_storage/test_generate_filename.py @@ -53,13 +53,20 @@ class GenerateFilenameStorageTests(SimpleTestCase): s.generate_filename(file_name) def test_storage_dangerous_paths_dir_name(self): - file_name = '/tmp/../path' + candidates = [ + ('tmp/../path', 'tmp/..'), + ('tmp\\..\\path', 'tmp/..'), + ('/tmp/../path', '/tmp/..'), + ('\\tmp\\..\\path', '/tmp/..'), + ] s = FileSystemStorage() - msg = "Detected path traversal attempt in '/tmp/..'" - with self.assertRaisesMessage(SuspiciousFileOperation, msg): - s.get_available_name(file_name) - with self.assertRaisesMessage(SuspiciousFileOperation, msg): - s.generate_filename(file_name) + for file_name, path in candidates: + msg = "Detected path traversal attempt in '%s'" % path + with self.subTest(file_name=file_name): + with self.assertRaisesMessage(SuspiciousFileOperation, msg): + s.get_available_name(file_name) + with self.assertRaisesMessage(SuspiciousFileOperation, msg): + s.generate_filename(file_name) def test_filefield_dangerous_filename(self): candidates = [ diff --git a/tests/file_storage/tests.py b/tests/file_storage/tests.py index 8969253e2b..66edbb204f 100644 --- a/tests/file_storage/tests.py +++ b/tests/file_storage/tests.py @@ -298,6 +298,12 @@ class FileStorageTests(SimpleTestCase): self.storage.delete('path/to/test.file') + def test_file_save_abs_path(self): + test_name = 'path/to/test.file' + f = ContentFile('file saved with path') + f_name = self.storage.save(os.path.join(self.temp_dir, test_name), f) + self.assertEqual(f_name, test_name) + @unittest.skipUnless(symlinks_supported(), 'Must be able to symlink to run this test.') def test_file_save_broken_symlink(self): """A new path is created on save when a broken symlink is supplied.""" |
