Summary
Unearth through 0.18.2 contains a path traversal vulnerability in its directory-containment validation. Malicious tar archives containing traversal paths or symlink members may cause files to be written outside the intended extraction directory when processed by a vulnerable application.
Affected context
The vulnerability occurs in applications that use Unearth's archive extraction functionality and rely on the affected is_within_directory check to constrain extracted paths. Risk is higher when an attacker can provide or influence tar archives processed by a service or local workflow, and when the process has write access to sensitive filesystem locations.
Exploit preconditions
- Attack surface: Tar archive extraction through Unearth
- Required access: Ability to supply or influence an archive that the vulnerable process will extract
- Trigger point: Path validation and file creation during archive extraction
- Why exploitation is possible: The containment check does not normalize paths before validation, allowing traversal components or symlink-related archive members to evade the intended directory boundary
Why this happens
The underlying bug is an incomplete path containment check. The is_within_directory function validates paths before applying canonical normalization, so syntactic path components can make an unsafe destination appear to be inside the permitted directory. Archive extraction that follows symlinks or trusts member names can then write outside the extraction root, mapping to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
Potential impact
- An attacker may write or overwrite files outside the intended extraction directory.
- The process may modify configuration, application, or user-controlled files.
- Arbitrary file writes could enable further code execution depending on permissions and file locations.
- Sensitive data or system integrity may be affected.
- A compromised extraction workflow could facilitate persistence or lateral impact.
General mitigation guidance
Mitigation generally focuses on making archive extraction path-safe by default and reducing trust in archive metadata.
Common defensive patterns include:
- Canonicalizing and normalizing extraction paths before containment checks.
- Rejecting absolute paths, traversal components, and unsafe symlink or hard-link members.
- Verifying that every resolved destination remains beneath the intended extraction root.
- Extracting into isolated, least-privileged temporary directories before moving approved files.
- Applying restrictive filesystem permissions and avoiding privileged extraction processes.
- Using archive libraries and APIs that provide safe extraction semantics by default.
How teams detect issues like this
Organizations can look for this class of issue through:
- Static analysis rules identifying path checks performed before canonicalization.
- Code review signals such as direct concatenation of archive member names with extraction directories.
- Tests covering traversal components, absolute paths, symlinks, hard links, and canonical path boundary cases.
- Runtime monitoring for extraction processes writing outside approved staging directories.
- Policy enforcement requiring isolated, least-privileged archive processing.
Automated security review tools may help identify unsafe path-joining and archive-extraction patterns.

