CVE-2024-21542
Luigi < 3.6.0 has an Arbitrary File Write vulnerability due to Zip Slip in archive extraction.
- CVSS 6.6
- CWE-29
- Input Validation and Sanitization
- Local
Versions of the package luigi before 3.6.0 are vulnerable to Arbitrary File Write via Archive Extraction (Zip Slip) due to improper destination file path validation in the _extract_packages_archive function.
- CWE
- CWE-29
- CVSS base score
- 6.6
- Published
- 2024-12-10
- OWASP
- A04 Insecure Design
- Orthogonal defect classification
- Interface
- Code defect classification
- Incorrect Check
- Category
- Input Validation and Sanitization
- Subcategory
- Path Traversal
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- luigi
- Fixed by upgrading
- Yes
Solution
Upgrade to Luigi 3.6.0 or later.
Vulnerable code sample
import zipfile
import os
def extract_packages_archive(archive_path, extract_dir):
with zipfile.ZipFile(archive_path, 'r') as zip_ref:
for file_info in zip_ref.infolist():
zip_ref.extract(file_info, extract_dir)Patched code sample
import os
import zipfile
from pathlib import Path
def extract_packages_archive(archive_path, extract_dir):
if not os.path.isabs(extract_dir):
raise ValueError("extract_dir must be an absolute path")
extract_dir = Path(extract_dir)
with zipfile.ZipFile(archive_path, 'r') as zip_ref:
for file_info in zip_ref.infolist():
extract_path = extract_dir.joinpath(file_info.filename)
if not extract_path.is_relative_to(extract_dir):
raise ValueError(f"Attempted zip slip: '{file_info.filename}' is not inside '{extract_dir}'")
extract_path.parent.mkdir(parents=True, exist_ok=True)
zip_ref.extract(file_info, str(extract_path))Payload
import zipfile
import os
zip_file = zipfile.ZipFile('malicious.zip', 'w')
zip_file.writestr('../etc/passwd', 'test')
zip_file.close()
Cite this entry
@misc{vaitp:cve202421542,
title = {{Luigi < 3.6.0 has an Arbitrary File Write vulnerability due to Zip Slip in archive extraction.
}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-21542},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-21542/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
