/

CVE-2026-23644

Severity:

HIGH RISK

(7.5)

Path Traversal in esm.sh Tar Archive Handling

CVE-2026-23644

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write Outside Intended 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

A path traversal vulnerability in esm.sh's tar archive handling allows malicious archives to write files to unintended locations on the server filesystem.

Because path.Clean only normalizes paths and does not block absolute or otherwise dangerous paths in tar entries, an attacker supplying a crafted tar file could cause file overwrite or placement outside the intended extraction directory.

Affected context

This issue affects components in esm.sh that extract or process tar archives supplied directly or indirectly by external input.

The vulnerability is relevant when:

  • Tar file contents are not fully trusted (e.g., uploaded by users or fetched from external sources), and
  • The extraction logic relies on path.Clean for safety without additional checks against absolute or parent-directory paths.

In such contexts, archive entries may be written outside the intended root extraction directory.

Exploit preconditions

  • Attack surface: Tar archive processing endpoints, jobs, or background tasks in esm.sh that handle externally controllable tar files.
  • Required access: Ability to influence or provide tar archives processed by the system (e.g., via an upload, remote fetch, or build pipeline input).
  • Trigger point: Extraction or processing of tar entries where paths are sanitized only with path.Clean but not validated against absolute paths or directory traversal patterns.
  • Why exploitation is possible: path.Clean removes redundant separators and resolves . / .., but it does not inherently reject absolute paths or enforce confinement to a specific base directory. Attackers can use absolute paths (and in some cases cleverly structured relative paths) to escape the intended extraction root.

Why this happens

The root cause is an overreliance on path normalization (path.Clean) as a security boundary for file extraction from tar archives.

This maps directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').

The code assumes that cleaned paths are safe, but does not implement additional checks to:

  • Reject absolute paths (e.g., beginning with /), or
  • Enforce that target paths remain within a designated base directory.

As a result, the extraction logic may write files outside the intended sandbox when processing malicious tar entries.

Potential impact

  • Overwrite of existing files on the server within the effective filesystem permissions of the esm.sh process
  • Placement of unexpected files or content in configuration or data directories
  • Potential alteration of cached packages, bundles, or artifacts served by the CDN
  • In certain deployments, escalation to broader system compromise if sensitive files or executable scripts are overwritten

General mitigation guidance

Effective mitigation focuses on strict path validation and directory confinement when handling archive contents:

  • Treat all archive entry paths as untrusted, regardless of prior normalization.
  • Reject tar entries whose paths are absolute or that resolve outside a designated extraction root after joining and cleaning.
  • Implement a robust "zip-slip" style defense: join the cleaned entry path to a known base directory and verify that the resulting path still has the base directory as its prefix.
  • Avoid writing files directly to operational or configuration directories; instead, extract to a controlled temporary directory and only promote vetted content.
  • Run archive-processing components with least-privilege file system permissions to limit blast radius if traversal occurs.

These patterns reduce dependence on any single normalization function and confine effects even under unexpected input.

How teams detect issues like this

Detection typically combines code-level analysis and operational monitoring:

  • Static analysis / code review:
  • Search for tar (or other archive) extraction routines that use path.Clean (or similar) without subsequently validating that the final path resides within a fixed base directory.
  • Flag logic that accepts archive entry names directly from untrusted sources and uses them in filesystem operations (os.Create, os.OpenFile, renames, etc.) without explicit traversal checks.
  • Review any custom extraction utilities for missing prefix checks or failure to reject absolute paths.
  • Policy and testing:
  • Add unit and integration tests with crafted tar archives containing absolute paths and ../ segments to ensure they are rejected or safely handled.
  • Integrate security-focused linters or SAST tools configured to recognize archive extraction anti-patterns and path traversal risks.
  • Runtime monitoring:
  • Log extraction destinations and watch for unexpected file writes outside the intended directories, where feasible, to surface anomalous behavior in production.

Sources

SourceLink
github.comgithub.com/esm-dev/esm.sh/commit/9d77b88c320733ff6689d938d85d246a3af9af16
github.comgithub.com/esm-dev/esm.sh/commit/c62ab83c589e7b421a0e1376d2a00a4e48161093
github.comgithub.com/esm-dev/esm.sh/security/advisories/GHSA-2657-3c98-63jq
pkg.go.devpkg.go.dev/vuln/GO-2025-4138

Frequently asked

questions

Exploitability depends on whether an attacker can control tar archives processed by esm.sh. If archive inputs come from untrusted or semi-trusted sources without additional validation, the issue may be directly exploitable; if archives are fully controlled and verified internally, the practical risk is lower.

Not necessarily. The key requirement is the ability to influence or supply tar files that the vulnerable extraction code processes. In some deployments, this might be gated behind authenticated APIs; in others, it could be triggered via public or automated ingestion mechanisms.

The safest approach is to enforce strict path confinement: normalize the entry path, join it with a designated base directory, and verify that the resulting path remains within that base. Reject entries with absolute paths or that resolve outside the allowed directory before any file operations occur.

Establish a standard archive-handling utility that enforces directory confinement and is reused across the codebase, include tests with malicious archive samples, and incorporate static analysis or code review checklists that specifically call out archive-based path traversal as a risk whenever file paths originate from external data.

Find out what's already
exploitable in your codebase.