/

CVE-2026-42574

Severity:

HIGH RISK

(7.5)

Path Traversal via Symlinks in apko APK Extraction

CVE-2026-42574

Deferred

Vulnerability type

Category:

Path Traversal via Symlinks

CWE:

CWE-22, CWE-59

Impact:

Arbitrary File Write on Host via Build Process

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 symlink-based path traversal vulnerability in apko allows crafted .apk packages to write files outside the intended build root during image construction.

If an attacker can influence the APK contents, they may be able to traverse a malicious symlink and overwrite or create files on the host system within the build user's writable paths.

Affected context

This issue affects environments where apko is used to build OCI container images from .apk packages, particularly in automated build pipelines or CI systems.

The vulnerability manifests during package extraction when the build process:

  • Trusts tar entries within .apk archives
  • Allows TypeSymlink entries whose targets resolve outside the configured build root
  • Subsequently creates directories or writes files that can traverse those symlinks

It is most relevant when untrusted or partially trusted APKs are included in the image build.

Exploit preconditions

  • Attack surface: The apko image build process handling .apk archives.
  • Required access: Ability to supply or influence crafted .apk packages consumed by apko (e.g., via a package repository, dependency injection, or build configuration).
  • Trigger point: Extraction of an APK that:
  1. Installs a TypeSymlink tar entry whose target points outside the build root.
  2. Includes a subsequent directory-creation or file-write entry that uses a path resolving through that symlink.
  • Why exploitation is possible: The extraction logic does not enforce strict root confinement when resolving symlink targets and file paths, allowing directory or file operations to escape the intended build root and reach host filesystem locations writable by the build user.

Why this happens

The underlying bug is a combination of path traversal and symlink handling weaknesses.

During tar/APK extraction, apko accepts TypeSymlink entries whose targets are not normalized and validated against the build root, and later file or directory entries can be created via paths that traverse this symlink.

This behavior maps to:

  • CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), because user-controlled archive contents can direct write operations outside the designated build root.
  • CWE-59: Improper Link Resolution Before File Access ('Link Following'), because the extraction process follows untrusted symlink targets without checking that they remain confined within the allowed directory tree.

The insecure pattern is trusting archive metadata (paths and symlink targets) as safe, without enforcing canonicalization and containment checks prior to filesystem operations.

Potential impact

  • Arbitrary file creation or overwrite on the host system within directories writable by the build user
  • Tampering with files used by other builds or services (e.g., configuration, scripts, or caches)
  • Indirect code execution if overwritten files are later executed, interpreted, or loaded as configuration
  • Compromise of build integrity, including the possibility of supply chain attacks via poisoned build artifacts

General mitigation guidance

Effective mitigation focuses on confining file operations to a strict root and hardening symlink handling during archive extraction.

Common defensive patterns include:

  • Canonicalizing all file paths (including symlink targets) and verifying they remain within the intended build root before any directory creation or file write.
  • Rejecting or sanitizing symlink entries whose targets resolve outside the build root, or disabling symlink creation entirely during extraction when not strictly required.
  • Performing path normalization that collapses .. and similar sequences prior to use, and enforcing a policy that forbids escaping the root directory.
  • Running build processes under minimally privileged users with limited filesystem access to reduce the blast radius of any escaped writes.
  • Isolating build environments (e.g., using chroots, containers, or dedicated volumes) so that even if path traversal occurs, sensitive host paths remain inaccessible.

How teams detect issues like this

Detection can target both code-level patterns and runtime behavior.

  • Static analysis and code review:
  • Flag archive extraction code that:
  • Trusts tar entry paths or symlink targets without canonicalization and containment checks.
  • Joins user-controlled paths directly with root directories without validating the resulting path.
  • Follows symlinks created from archive contents without verifying they stay under a configured root.
  • Look for missing checks around .. segments, absolute paths, and symlink targets in extraction logic.
  • Policy enforcement:
  • Enforce secure extraction utilities or wrappers that apply path-confinement logic consistently across build tools.
  • Apply repository policies that restrict ingestion of APKs from untrusted sources, especially in critical build pipelines.
  • Runtime monitoring:
  • Observe build environments for unexpected file writes outside expected build directories.
  • Use filesystem auditing in sensitive build hosts to detect abnormal path access patterns, such as writes into system directories by build processes.

Automated code scanning tools and secure coding checklists can be configured with rules specific to archive extraction and symlink handling to surface similar issues early.

Sources

SourceLink
github.comgithub.com/chainguard-dev/apko/commit/f5a96e1299ac81c7ea9441705ec467688086f442
github.comgithub.com/chainguard-dev/apko/pull/2187
github.comgithub.com/chainguard-dev/apko/releases/tag/v1.2.5
github.comgithub.com/chainguard-dev/apko/security/advisories/GHSA-qq3r-w4hj-gjp6

Frequently asked

questions

It can be, depending on how apko is integrated. If an attacker can remotely supply or influence APK packages consumed by a build pipeline (for example via a package repository or pull request that introduces a new dependency), they may exploit this vulnerability indirectly through the build system.

The attacker needs the ability to introduce or modify .apk files used by apko, such as controlling an APK repository, contributing crafted packages to a build, or intercepting package distribution. They do not need shell access to the build host, but they must influence the archive contents processed by apko.

The safest pattern is to enforce strict path confinement for all file operations during archive extraction:

  • Normalize and canonicalize paths and symlink targets.
  • Reject any entries whose resolved paths fall outside the designated root.
  • Avoid following untrusted symlinks where possible.

Combining these safeguards with least-privilege execution and isolated build environments provides defense in depth.

Preventive strategies include:

  • Standardizing on hardened archive extraction routines that perform root confinement checks and safe symlink handling.
  • Incorporating static analysis rules and code review checklists focused on path traversal and link-following issues.
  • Restricting the use of untrusted packages in critical build processes and validating the provenance of dependencies.
  • Regularly testing build tooling with adversarial inputs (e.g., fuzzing archive parsers) to uncover path and symlink handling flaws early.
Find out what's already
exploitable in your codebase.