CVE-2025-4138

7.5 HIGH

📋 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

Products:
  • Python
  • Applications using Python's tarfile module
Versions: All Python versions using tarfile module with filter parameter
Operating Systems: All operating systems running Python
Default Config Vulnerable: ⚠️ Yes
Notes: Python 3.14+ has filter='data' by default, making it vulnerable by default. Earlier versions require explicit filter='data' or filter='tar' to be vulnerable.

⚠️ 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.

Recommended Actions:
  1. Review the CVE details at NVD
  2. Check vendor security advisories for your specific version
  3. Test if the vulnerability is exploitable in your environment
  4. 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.

🌐 Internet-Facing: MEDIUM - Applications processing user-uploaded tar files are vulnerable, but exploitation requires specific tar archive creation.
🏢 Internal Only: LOW - Internal systems typically process trusted archives, reducing attack surface.

🎯 Exploit Status

Public PoC: ⚠️ Yes
Weaponized: LIKELY
Unauthenticated Exploit: ⚠️ Yes
Complexity: LOW

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'

all

Set 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

all

Do 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

📤 Share & Export