/

CVE-2025-69874

Severity:

CRITICAL RISK

(9.8)

Path Traversal in nanotar Archive Extraction Routines

CVE-2025-69874

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Intended Directory

Severity:

CRITICAL RISK

(9.8)

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

nanotar through version 0.2.0 contains a path traversal vulnerability in its parseTar() and parseTarGzip() functions that mishandles file paths within tar archives.

An attacker who can supply a crafted tar file can write files outside the intended extraction directory, potentially overwriting sensitive system or application files when the archive is processed.

Affected context

This vulnerability affects applications that use nanotar (through 0.2.0) to parse or extract untrusted tar or tar.gz archives via parseTar() or parseTarGzip().

It is most relevant when:

  • Archives are accepted from remote or otherwise untrusted sources (e.g., user uploads, network services, automated import feeds), and
  • The calling code assumes nanotar will safely confine extracted paths to a specific directory without performing its own validation.

The issue is triggered during archive parsing and extraction, before any higher-level business logic may enforce additional checks.

Exploit preconditions

  • Attack surface: Any interface that processes tar or tar.gz archives using nanotar (e.g., file upload endpoints, API ingestion services, CLI tools).
  • Required access: Ability to supply or influence the tar archive contents (remote or local, depending on the application design).
  • Trigger point: Invocation of parseTar() or parseTarGzip() on a crafted archive that contains entries with directory traversal sequences such as ../.
  • Why exploitation is possible: The library does not correctly normalize and validate archive entry paths against the intended extraction root, allowing relative paths to escape the target directory and point to arbitrary locations in the filesystem.

Why this happens

The underlying bug is a classic directory traversal issue as described by CWE-22.

nanotar trusts the file path metadata stored in tar entries and does not robustly sanitize or canonicalize those paths before using them to determine where files will be written.

When an archive entry contains traversal tokens such as ../ or absolute paths, the computed destination is allowed to escape the designated extraction directory.

Abstractly, this reflects an insecure pattern where user-controlled path components are joined with a base directory without:

  • Normalizing the path to its canonical form, and
  • Enforcing that the resulting path still resides under the intended root.

Potential impact

  • Overwriting application configuration files that the process has permission to modify.
  • Dropping malicious scripts or binaries into locations where they may later be executed.
  • Tampering with log files or data files to manipulate application behavior or cover tracks.
  • Writing files into web-accessible directories, potentially enabling stored cross-site scripting or web shell deployment in some environments.
  • Facilitating privilege escalation if combined with other misconfigurations (e.g., overwriting files read by higher-privileged services).

General mitigation guidance

Effective mitigation focuses on constraining file paths derived from untrusted archives and treating archive contents as hostile input:

  • Normalize and canonicalize each archive entry path before use, resolving . and .. segments and symbolic links where applicable.
  • Enforce that the canonical destination path remains within the expected extraction directory; reject or skip entries that would escape this boundary.
  • Prefer extraction helpers or libraries that implement secure path validation by default and are explicitly hardened against directory traversal.
  • Run archive processing code with the least privileges necessary, restricting filesystem permissions so that even if traversal occurs, damage is limited.
  • Store extracted files under dedicated, non-critical directories that are not directly executed by the runtime or served without additional checks.

These patterns help reduce reliance on any single library implementation and safeguard against similar issues across different components.

How teams detect issues like this

Detection typically combines code-level review with behavioral monitoring:

  • Static analysis and code review:
  • Search for use of nanotar's parseTar() and parseTarGzip() when handling untrusted input.
  • Flag patterns where archive entry paths are concatenated directly with base directories without normalization and boundary checks.
  • Review for absence of canonical path comparison (e.g., checking that realpath/equivalent remains under the intended root).
  • Security testing:
  • Incorporate malicious tar archives containing ../ sequences and absolute paths into automated test suites and CI pipelines.
  • Use dynamic analysis tools or fuzzers that generate adversarial archive structures to probe extraction behavior.
  • Operational monitoring:
  • Monitor for unexpected file creation or modification outside designated upload/extraction directories.
  • Employ filesystem integrity monitoring in sensitive areas to detect unauthorized writes that may indicate exploitation.

Automated code scanning tools, including SAST solutions, can be configured with custom rules to highlight directory traversal risks in archive handling code.

Sources

SourceLink
github.comgithub.com/EthanKim88/ethan-cve-disclosures/blob/main/CVE-2025-69874-nanotar-Path-Traversal.md
github.comgithub.com/unjs/nanotar
npmjs.comnpmjs.com/package/nanotar

Frequently asked

questions

Yes, if your application accepts tar or tar.gz archives from remote users or external systems and processes them with nanotar, an attacker can exploit this issue over the network by supplying a crafted archive.

The attacker needs the ability to provide or influence the tar archive processed by nanotar.

They do not require shell access to the server; the vulnerability is triggered when the application itself processes the malicious archive.

The safest approach is to enforce strict path normalization and boundary checks on all archive entries before file creation.

Only allow files to be written if their canonical paths remain within an approved extraction directory, and ignore or reject any entries that attempt to escape that directory.

Establish a standard pattern for handling filesystem paths derived from untrusted input: canonicalize paths, perform containment checks against a known root, and avoid writing directly into sensitive or executable locations.

Incorporate security reviews and automated tests for archive and file handling features so that directory traversal issues are detected early in development.

Find out what's already
exploitable in your codebase.