Summary
A path traversal vulnerability in the jaraco.context.tarball() helper can allow malicious tar archives to write files outside the intended extraction directory.
When crafted paths with ../ sequences are processed, attackers may cause arbitrary filesystem locations to be overwritten, especially in scenarios that automatically unpack untrusted or semi-trusted archives.
Affected context
The vulnerability occurs when applications use jaraco.context.tarball() (versions ≥5.2.0 and <6.1.0) to extract tar or nested tar archives, while assuming the helper will safely keep all files within a target directory.
It is relevant in workflows that automatically unpack archives provided by external sources (e.g., uploads, package imports, CI artifacts) without additional path validation or sandboxing.
Exploit preconditions
- Attack surface: Archive extraction logic that relies on
jaraco.context.tarball()for processing.tar,.tar.gz, or nested tar files. - Required access: Ability to supply or influence the tar file contents (e.g., file uploads, repository content, remotely fetched archives).
- Trigger point: Invocation of
jaraco.context.tarball()on a crafted archive containing paths with../segments or nested tarballs with traversal paths. - Why exploitation is possible: The
strip_first_componentfilter strips only the first path component but does not normalize or reject..segments, allowing entries likedummy_dir/../../etc/passwdto become../../etc/passwdand to be written relative to the extraction root.
Why this happens
The bug stems from an incomplete normalization and validation of archive member paths before extraction.
The strip_first_component logic splits a path around the first / and takes the remainder without checking for directory traversal patterns (../) or enforcing that the resulting path stays within the intended destination.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controlled paths are used in file operations without robust canonicalization and containment checks.
Potential impact
- Overwriting existing files on the filesystem that are writable by the extraction process
- Placing attacker-controlled files in sensitive locations (e.g., config directories, application data paths)
- Tampering with application configuration (such as
.envor YAML files) to alter behavior or inject secrets - Laying groundwork for further attacks, including code execution, if a written file is later loaded or executed by the application or environment
General mitigation guidance
Mitigation generally focuses on enforcing strict path safety during archive extraction and reducing the trust placed in archive contents.
Recommended defensive patterns include:
- Normalizing each archive member path (e.g., via realpath-like mechanisms) and ensuring it resolves inside the intended destination directory before extracting.
- Explicitly rejecting any archive entry that contains
.., absolute paths, or other disallowed components. - Using extraction routines or helper libraries that are designed to be Zip Slip–safe by default.
- Running extraction processes with least-privilege OS accounts and restricting write access to only non-sensitive directories.
- Treating nested archives (e.g., inner tarballs) with the same validation rules as top-level entries and avoiding automatic recursive extraction where it is not essential.
How teams detect issues like this
Detection typically involves a mix of code scanning and behavioral checks:
- Static analysis: Search for uses of
jaraco.context.tarball()and verify that no additional path validation is performed on archive members; flag patterns that manipulate paths but do not normalize or constrain them. - Code review: Look for custom extraction helpers that strip path components without checking for traversal (
../) or absolute paths; verify that nested archive extraction uses the same safeguards. - Policy enforcement: Establish guidelines that any file extraction from untrusted archives must include canonicalization and directory-bound checks; integrate these policies into pull request templates and review checklists.
- Runtime monitoring: Where feasible, monitor for unexpected write operations outside expected extraction directories during archive handling, which can highlight potential exploitation attempts.

