Skip to main content
CVE Vulnerability Database
Vulnerability Database/CVE-2026-29509

CVE-2026-29509: Patool Path Traversal Vulnerability

CVE-2026-29509 is a path traversal flaw in Patool before version 4.0.5 that allows attackers to write arbitrary files using malicious archives. This article covers the technical details, affected versions, and steps to mitigate.

Published:

CVE-2026-29509 Overview

CVE-2026-29509 is a path traversal vulnerability [CWE-22] in Patool versions before 4.0.5 when running on Python versions before 3.12. The flaw resides in the safe_extract() function within patoolib/programs/py_tarfile.py. The is_within_directory() helper relies on os.path.commonprefix() for character-level string comparison instead of proper path-level comparison. A crafted archive containing specially designed member paths bypasses the containment check, letting attackers write arbitrary files outside the intended extraction directory.

Critical Impact

Attackers who convince a user to extract a malicious archive can write files to arbitrary filesystem locations, potentially leading to code execution through overwritten configuration files or scripts.

Affected Products

  • Patool versions before 4.0.5
  • Deployments running on Python versions before 3.12
  • Applications and pipelines using Patool for archive extraction on affected Python runtimes

Discovery Timeline

  • 2026-06-26 - CVE-2026-29509 published to NVD
  • 2026-06-27 - Last updated in NVD database

Technical Details for CVE-2026-29509

Vulnerability Analysis

Patool is a Python-based archive file manager that wraps external tools to handle multiple archive formats. The safe_extract() function is designed to prevent Zip Slip-style attacks by validating that extracted member paths remain inside the target directory. That validation depends on is_within_directory(), which delegates the containment check to Python's os.path.commonprefix().

The function os.path.commonprefix() compares strings character by character rather than by path components. As a result, a target directory /tmp/extract shares a common prefix with /tmp/extract-evil/../../etc/passwd or /tmp/extractmalicious, and the check returns a value that satisfies the containment condition. The archive member is then written outside the intended directory.

Root Cause

The root cause is the incorrect use of os.path.commonprefix() for security-sensitive path containment checks. Python 3.12 introduced tarfile filters that replace the vulnerable custom logic, which is why the flaw only affects Python versions before 3.12. The proper approach uses os.path.commonpath() or explicit path normalization with os.path.realpath() followed by prefix validation on normalized absolute paths.

Attack Vector

An attacker crafts a tar archive containing member entries whose resolved paths escape the extraction directory. Delivery vectors include email attachments, downloaded packages, upload endpoints, or supply chain components. When a victim extracts the archive using Patool on Python versions before 3.12, the flawed containment check allows writes to arbitrary locations such as ~/.ssh/authorized_keys, cron directories, or startup scripts. Exploitation requires user interaction to trigger extraction.

The vulnerability mechanism is described in the VulnCheck Security Advisory and addressed in the GitHub Release 4.0.5.

Detection Methods for CVE-2026-29509

Indicators of Compromise

  • Files written outside the intended extraction directory following a Patool extraction operation
  • Modifications to sensitive files such as ~/.ssh/authorized_keys, /etc/cron.d/*, or user shell initialization files that correlate with archive processing activity
  • Archive members containing path traversal sequences such as ../ or absolute paths in tar listings

Detection Strategies

  • Inventory Python environments and identify installations of patool with versions earlier than 4.0.5 combined with Python interpreters older than 3.12
  • Inspect archive contents before extraction using tar -tvf or equivalent listing commands to flag members with parent directory references or absolute paths
  • Audit build systems, CI/CD pipelines, and file-processing services that call Patool for archive handling

Monitoring Recommendations

  • Monitor file creation events in sensitive directories originating from Python processes running archive extraction workloads
  • Log Patool invocations and correlate them with subsequent write events outside declared output directories
  • Track package inventory changes to detect installations of vulnerable Patool versions across development and production hosts

How to Mitigate CVE-2026-29509

Immediate Actions Required

  • Upgrade Patool to version 4.0.5 or later using pip install --upgrade patool
  • Upgrade Python runtimes to version 3.12 or later where feasible, which enables safer tarfile extraction filters
  • Audit all services and scripts that process untrusted archives using Patool and prioritize remediation for internet-facing components

Patch Information

The fix is included in Patool 4.0.5. Details are available in the GitHub Change Log and the GitHub Release 4.0.5 notes. The patch replaces the character-level prefix comparison with a proper path-component containment check.

Workarounds

  • Restrict archive extraction to isolated, unprivileged directories using containers, chroot environments, or dedicated service accounts with minimal filesystem access
  • Validate archive member paths programmatically before extraction, rejecting entries containing .. sequences or absolute paths
  • Avoid extracting archives received from untrusted sources on hosts running Python versions before 3.12 with vulnerable Patool releases

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Default Legacy - Prefooter | Experience the World’s Most Advanced Cybersecurity Platform

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.