CVE-2024-12718: Bypass extraction filter to modify file metadata outside extraction directory
Allows modifying some file metadata (e.g. last modified) with filter="data" or file permissions (chmod) with filter="tar" of files outside the extraction directory. You are affected by this vulnerability if using the tarfile module to extract untrusted tar archives using TarFile.extractall() or TarFile.extract() using the filter= parameter with a value of "data" or "tar". See the tarfile extraction filters documentation https://docs.python.org/3/library/tarfile.html#tarfile-extraction-filter for more information. Only Python versions 3.12 or later are affected by these vulnerabilities, earlier versions don't include the extraction filter feature.
Note that for Python 3.14 or later the default value of filter= changed from "no filtering" to "data", so if you are relying on this new default behavior then your usage is also affected.
Note that none of these vulnerabilities significantly affect the installation of source distributions which are tar archives as source distributions already allow arbitrary code execution during the build process. However when evaluating source distributions it's important to avoid installing source distributions with suspicious links.
Other sources
Bypass extraction filter to modify file metadata outside extraction directory
— Microsoft
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.9.19-14 - Upgrade
Upgrade to a fixed release to a version that resolves this vulnerability.
Fixed in 3.12.9-2 - Configuration
When extracting untrusted tar archives with tarfile.TarFile.extractall() or tarfile.TarFile.extract(), do not use filter="data" or filter="tar". The vulnerability affects Python versions 3.12 and later when using tarfile extraction filters with those values and may allow modifying file metadata (including last-modified and chmod) outside the extraction directory.
Python tarfile (TarFile.extractall / TarFile.extract) filter parameter = (do not use "data" or "tar" for untrusted archives) - Compensating control
Avoid installing/extracting source distributions (tar archives) that contain suspicious links when evaluating source distributions.
Event History
Frequently Asked Questions
What is the severity of CVE-2024-12718?
CVE-2024-12718 has been rated as a medium severity vulnerability due to its potential impact on file metadata and permissions.
How do I fix CVE-2024-12718?
To mitigate CVE-2024-12718, avoid extracting untrusted tar archives using the tarfile module in affected versions of Python.
Which versions of Python are affected by CVE-2024-12718?
CVE-2024-12718 affects Python versions starting from 3.12 up to but not explicitly limited to 3.14.
What are the consequences of CVE-2024-12718?
The consequences of CVE-2024-12718 include the ability to modify file metadata and permissions of files outside the designated extraction directory.
Is there a workaround for CVE-2024-12718?
As a workaround for CVE-2024-12718, ensure that only trusted tar archives are processed and consider using alternative methods to extract tar files.