Severity:

HIGH RISK

(7.5)

Path Traversal in Windows via shutil.unpack_archive ZIP

CVE-2026-3087

Modified

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Target Directory

Severity:

HIGH RISK

(7.5)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

On Windows, Python's shutil.unpack_archive() may extract ZIP entries with absolute drive paths (e.g., C:\...) outside the intended target directory, unlike its behavior on other platforms.

When applications unpack untrusted ZIP archives on Windows using this API, an attacker could place files in arbitrary locations on the filesystem, potentially overwriting or planting malicious files.

Affected context

This vulnerability occurs in Windows environments where Python applications use shutil.unpack_archive() to process ZIP files, especially when those archives come from external or partially trusted sources.

The issue is triggered when ZIP entries contain absolute Windows paths including a drive letter (such as C:\path\to\file), allowing extracted files to bypass the caller's specified extraction directory.

The risk is higher in services or tools that automatically unpack user-supplied archives without additional path validation.

Exploit preconditions

  • Attack surface: Any Python-based functionality on Windows that calls shutil.unpack_archive() on ZIP files.
  • Required access: Ability to supply or influence the contents of a ZIP archive processed by the application (e.g., file upload, plugin package, backup restore).
  • Trigger point: The moment the application invokes shutil.unpack_archive() to extract the attacker-controlled ZIP into a target directory.
  • Why exploitation is possible: On Windows, shutil.unpack_archive() does not sufficiently normalize or confine absolute drive-based paths contained in ZIP entries, allowing extraction to paths outside the designated output directory.

Why this happens

The underlying issue is improper neutralization of file paths during extraction, corresponding to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.

On Windows, shutil.unpack_archive() allows ZIP entries with absolute drive paths to be used as-is, instead of rewriting or rejecting them to ensure they remain within the caller-specified extraction root.

Because paths are not consistently sanitized or restricted, archive authors can embed absolute paths that escape the trusted directory boundary, violating the expectation that extraction is confined to the chosen target directory.

Potential impact

  • Attacker-controlled files may be written to arbitrary locations on the Windows filesystem accessible by the running process.
  • Existing files could be overwritten, potentially altering configuration, logs, or application resources.
  • Malicious executables, scripts, or DLLs could be planted in locations that may later be executed by other components.
  • Application integrity and data integrity could be compromised through unauthorized file modification.
  • In certain deployment setups, this could contribute to privilege escalation or lateral movement when combined with other weaknesses.

General mitigation guidance

Effective mitigation focuses on enforcing strict directory confinement for extracted archives and treating all archive paths as untrusted input:

  • Normalize and validate archive member paths before writing to disk, rejecting entries with absolute drive paths, UNC paths, or segments that escape the intended root directory.
  • Implement a safe extraction wrapper that joins each member's path to the target directory, resolves it, and confirms it still lies under the intended root before creating files.
  • Treat archive uploads as untrusted data: limit where extracted files can be written, and avoid extracting with elevated privileges or sensitive working directories.
  • Use defense-in-depth by running archive processing under least-privileged accounts and restricting filesystem permissions for directories that should never be modified by archive extraction.
  • Consider separate sandboxed or temporary locations for unpacking archives, followed by a controlled copy/move of only the validated files to their final destinations.

How teams detect issues like this

Detection typically combines code-level review with behavioral monitoring:

  • Static analysis / code review:
  • Search for uses of shutil.unpack_archive() and other archive APIs, especially in code paths handling user-supplied ZIP files on Windows.
  • Flag extraction code that does not normalize or validate member paths, or that directly trusts paths from archive entries.
  • Review for absence of checks against absolute paths, drive letters, or traversal segments (..), and lack of canonicalization (e.g., using os.path.realpath or similar).
  • Policy and tooling:
  • Introduce secure coding guidelines for archive handling in the codebase and enforce them via pull request templates and automated linters where possible.
  • Use security scanning tools or custom scripts to identify high-risk file extraction patterns across repositories.
  • Runtime monitoring:
  • Log extraction operations and unexpected writes outside designated directories, especially during archive handling workflows.

Frequently asked

questions

It can be, if an application running on Windows accepts ZIP files from remote users (e.g., uploads, package feeds, backups) and automatically unpacks them using shutil.unpack_archive() without sanitizing paths. In such setups, a remote attacker could influence where files are written.

The attacker needs the ability to supply or modify a ZIP archive that the vulnerable Python code extracts. They do not necessarily need direct filesystem access; control over the archive contents processed by the application is sufficient.

Wrap archive extraction with a path validation routine that treats all archive member paths as untrusted. For each entry, construct the target path under the intended output directory, canonicalize it, and ensure it still resides within that directory; reject or rewrite entries that fail this check, particularly those using absolute drive paths.

Establish standard, reusable utilities for safe archive extraction and mandate their use across projects. Combine this with coding guidelines that forbid direct use of low-level extraction APIs on untrusted archives without path confinement, regular security reviews for file handling logic, and automated checks that flag risky extraction patterns in Windows-specific code paths.

Find out what's already
exploitable in your codebase.