CVE-2025-4138
📋 TL;DR
This vulnerability in Python's tarfile module allows attackers to bypass extraction filters, enabling symlink attacks that can write files outside the intended destination directory and modify file metadata. It affects Python applications using TarFile.extractall() or TarFile.extract() with filter='data' or filter='tar' on untrusted tar archives. Python 3.14+ users are also affected due to the new default filter='data' behavior.
💻 Affected Systems
- Python
- Applications using Python's tarfile module
⚠️ Manual Verification Required
This CVE does not have specific version information in our database, so automatic vulnerability detection cannot determine if your system is affected.
Why? The CVE database entry doesn't specify which versions are vulnerable (no version ranges provided by the vendor/NVD).
🔒 Custom verification scripts are available for registered users. Sign up free to download automated test scripts.
- Review the CVE details at NVD
- Check vendor security advisories for your specific version
- Test if the vulnerability is exploitable in your environment
- Consider updating to the latest version as a precaution
⚠️ Risk & Real-World Impact
Worst Case
Arbitrary file write leading to remote code execution, privilege escalation, or data corruption by overwriting critical system files.
Likely Case
Directory traversal allowing attackers to write files to unintended locations, potentially leading to data leakage or denial of service.
If Mitigated
Limited impact if only trusted archives are processed or proper sandboxing is implemented.
🎯 Exploit Status
Exploitation requires creating a malicious tar archive with symlinks pointing outside the extraction directory. The GitHub gist provides technical details.
🛠️ Fix & Mitigation
✅ Official Fix
Patch Version: Python 3.13.2, 3.12.7, 3.11.12, 3.10.14, 3.9.20
Vendor Advisory: https://gist.github.com/sethmlarson/52398e33eff261329a0180ac1d54f42f
Restart Required: No
Instructions:
1. Update Python to patched versions: 3.13.2, 3.12.7, 3.11.12, 3.10.14, or 3.9.20. 2. For Python 3.14+, ensure you're using the latest version with the fix. 3. Update all applications using Python's tarfile module.
🔧 Temporary Workarounds
Use filter='fully_trusted'
allSet filter='fully_trusted' when extracting archives, which disables filtering but should only be used with trusted sources.
tar.extractall(filter='fully_trusted')
tar.extract(filter='fully_trusted')
Avoid filter parameter
allDo not use filter='data' or filter='tar' parameters when extracting untrusted archives.
tar.extractall()
tar.extract()
🧯 If You Can't Patch
- Only extract tar archives from trusted sources
- Implement additional validation of tar archives before extraction, checking for suspicious symlinks
🔍 How to Verify
Check if Vulnerable:
Check if your Python code uses TarFile.extractall() or TarFile.extract() with filter='data' or filter='tar' on untrusted archives.
Check Version:
python --version
Verify Fix Applied:
Update Python to patched version and test extraction of archives with symlinks to ensure they're properly filtered.
📡 Detection & Monitoring
Log Indicators:
- Failed file writes outside expected directories
- Unexpected symlink creation during archive extraction
Network Indicators:
- Uploads of tar archives to vulnerable endpoints
SIEM Query:
Process execution logs showing tar extraction with filter parameters, followed by file writes to unexpected locations
🔗 References
- https://gist.github.com/sethmlarson/52398e33eff261329a0180ac1d54f42f
- https://github.com/python/cpython/commit/19de092debb3d7e832e5672cc2f7b788d35951da
- https://github.com/python/cpython/commit/28463dba112af719df1e8b0391c46787ad756dd9
- https://github.com/python/cpython/commit/3612d8f51741b11f36f8fb0494d79086bac9390a
- https://github.com/python/cpython/commit/4633f3f497b1ff70e4a35b6fe2c907cbe2d4cb2e
- https://github.com/python/cpython/commit/9c1110ef6652687d7c55f590f909720eddde965a
- https://github.com/python/cpython/commit/9e0ac76d96cf80b49055f6d6b9a6763fb9215c2a
- https://github.com/python/cpython/commit/aa9eb5f757ceff461e6e996f12c89e5d9b583b01
- https://github.com/python/cpython/commit/dd8f187d0746da151e0025c51680979ac5b4cfb1
- https://github.com/python/cpython/issues/135034
- https://github.com/python/cpython/pull/135037
- https://mail.python.org/archives/list/security-announce@python.org/thread/MAXIJJCUUMCL7ATZNDVEGGHUMQMUUKLG/