mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed CVE-2021-45452 -- Fixed potential path traversal in storage subsystem.
Thanks to Dennis Brinkrolf for the report.
This commit is contained in:
committed by
Carlton Gibson
parent
761f449e0d
commit
6d343d01c5
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user