/

CVE-2026-25121

Severity:

HIGH RISK

(7.5)

Path Traversal in apko dirFS Filesystem Abstraction

CVE-2026-25121

Analyzed

Vulnerability type

Category:

Path Traversal

CWE:

CWE-23, CWE-22

Impact:

Filesystem Escapes and Unintended File/Directory Creation

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

apko's dirFS abstraction contains a path traversal flaw where directory and symlink creation routines do not verify that computed paths remain within the intended installation root.

An attacker who can introduce a malicious APK package (for example, via a compromised or typosquatted repository) could use crafted paths to create directories or symlinks outside the target root, potentially redirecting writes or influencing the container filesystem layout.

Affected context

This vulnerability affects environments that use apko (versions 0.14.8 to before 1.1.1) to build OCI container images from APK packages.

It specifically involves the dirFS filesystem abstraction in pkg/apk/fs/rwosfs.go, where MkdirAll, Mkdir, and Symlink rely on filepath.Join() alone to construct target paths.

When apko processes APK packages that contain crafted file paths or symlinks, the code does not ensure that the resultant paths stay confined to the configured installation root directory, allowing potential writes outside that root.

Exploit preconditions

  • Attack surface: The APK package contents processed during apko image builds (file paths, directory entries, symlinks).
  • Required access: Ability to influence which APK packages are installed (e.g., publishing a malicious package to a repository, controlling a typosquatted package name, or compromising a package source).
  • Trigger point: apko invoking filesystem operations (MkdirAll, Mkdir, Symlink) on paths derived from package metadata during image build.
  • Why exploitation is possible: The implementation uses filepath.Join(baseDir, userPath) without subsequently validating that the normalized resulting path still resides within baseDir. Crafted relative paths (e.g., containing traversal segments) or symlink targets can cause operations to escape the intended root.

Why this happens

The core issue is an incomplete validation of file system paths constructed from partially untrusted input.

The dirFS abstraction assumes that joining a base root with a user-controlled or package-controlled subpath via filepath.Join() is sufficient to maintain confinement.

However, without explicit checks that the final, cleaned path remains a descendant of the base directory, the code is vulnerable to CWE-23: Relative Path Traversal.

This pattern occurs whenever software treats relative paths from external sources as inherently safe, omitting normalization and enforcement of directory boundaries before performing filesystem side effects.

Potential impact

  • Creation of directories outside the intended installation root used by apko.
  • Creation of symlinks that point outside the root, potentially redirecting later writes or reads.
  • Interference with the container filesystem layout, such as redirecting configuration or binary locations.
  • Increased risk of follow-on vulnerabilities where other components trust the filesystem layout produced by apko.
  • Facilitation of supply-chain manipulation within built images, depending on how the escaped paths are later used.

General mitigation guidance

Effective mitigation focuses on enforcing strict path confinement and treating package-controlled paths as untrusted:

  • Normalize and validate all derived paths after joining with the base directory, ensuring they remain within the intended root (e.g., by comparing cleaned prefixes or using chroot-like abstractions).
  • Implement helper APIs that encapsulate safe path handling for all filesystem operations, rather than duplicating ad-hoc joins.
  • Treat symlink creation and resolution as high-risk operations; restrict or sanitize symlink targets that originate from package metadata.
  • Apply a defense-in-depth model where build tools operate with minimal privileges on isolated build roots or temporary filesystems.
  • Prefer secure-by-default path utilities and enforce coding guidelines that forbid direct use of unsafe join patterns on untrusted input.

How teams detect issues like this

Detection generally combines code-level and build-time analysis:

  • Use static analysis rules to flag instances where filepath.Join() (or equivalent) is used with untrusted or package-derived components without subsequent boundary checks.
  • During code review, treat any filesystem abstraction that accepts external or package-controlled paths as security-sensitive, verifying that all operations enforce root confinement.
  • Instrument build pipelines with logging for unusual or out-of-tree paths encountered during image assembly, and alert on attempts to write outside expected directories.
  • Employ automated secure code review tools or linters that recognize common path traversal antipatterns, particularly in functions that create directories, files, or symlinks.

Sources

SourceLink
github.comgithub.com/chainguard-dev/apko/commit/d8b7887a968a527791b3c591ae83928cb49a9f14
github.comgithub.com/chainguard-dev/apko/security/advisories/GHSA-5g94-c2wx-8pxw

Frequently asked

questions

It can be, if an attacker can remotely influence which APK packages apko consumes—such as through a compromised repository, a typosquatted package, or any mechanism that feeds attacker-controlled package metadata into the build process.

The attacker must be able to introduce or control an APK package used by apko. Direct access to the build host is not required if the package source or dependency resolution process can be influenced.

Enforce strict path confinement by validating that any path derived from external or package-controlled data remains within the intended base directory before performing filesystem operations, and centralize this logic in a reusable, well-reviewed abstraction.

Treat all file paths from external artifacts (packages, archives, user input) as untrusted, normalize and validate them against explicit directory boundaries, document these requirements in coding standards, and automate checks for unsafe path-joining patterns in CI and code review.

Find out what's already
exploitable in your codebase.