CVE-2024-6232
CPython vulnerability allows ReDoS via excessive regex backtracking in tarfile.
- CVSS 7.5
- CWE-1333
- Input Validation and Sanitization
- Remote
There is a MEDIUM severity vulnerability affecting CPython. Regular expressions that allowed excessive backtracking during tarfile.TarFile header parsing are vulnerable to ReDoS via specifically-crafted tar archives.
- CWE
- CWE-1333
- CVSS base score
- 7.5
- Published
- 2024-09-03
- OWASP
- A03 Injection
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- Python 3.10.
- Fixed by upgrading
- Yes
Solution
Upgrade to CPython 3.10.8 or later, which includes a fix for this vulnerability.
Vulnerable code sample
import tarfile
import re
def tarfile_extract(tar_path, extract_path):
with tarfile.open(tar_path, 'r') as tar:
for member in tar.getmembers():
if re.match(r'^(.*?)(\.\.?)', member.name):
tar.extract(member, path=extract_path)Patched code sample
import tarfile
import re
def tarfile_extract(tar_path, extract_path):
with tarfile.open(tar_path, 'r') as tar:
for member in tar.getmembers():
if re.match(r'^[\w\-. ]+$', member.name):
tar.extract(member, path=extract_path)
else:
raise ValueError("Unsafe tar member name detected")Payload
# Example of a specially-crafted tar archive that triggers excessive backtracking
# This is a conceptual representation and cannot be executed as-is.
# Create a tar file with a maliciously crafted file name
# The file name is designed to exploit the regex vulnerability
# The actual creation of such a tar file would require a specific setup and is not provided here.
malicious_payload.tar:
"a" * 1000 + "!" + "b" * 1000 + ".." # Example of a long repetitive pattern
Cite this entry
@misc{vaitp:cve20246232,
title = {{CPython vulnerability allows ReDoS via excessive regex backtracking in tarfile.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2024},
note = {VAITP Python Vulnerability Dataset, entry CVE-2024-6232},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-6232/}}
}
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 ::
