/

CVE-2026-28406

Severity:

HIGH RISK

(8.2)

Path Traversal in Kaniko Build Context Handling

CVE-2026-28406

Modified

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22

Impact:

Arbitrary File Write and Potential Code Execution

Severity:

HIGH RISK

(8.2)

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

Kaniko's build context extraction logic allows tar entries with directory traversal sequences (such as ../outside.txt) to write files outside the intended destination directory.

In environments where Kaniko has access to registry credentials and helper binaries, an attacker who controls or tampers with the build context may be able to place files that lead to code execution within the executor process.

Affected context

The vulnerability occurs when Kaniko unpacks a build context archive inside the executor, typically within a container or Kubernetes pod.

It is relevant in setups where:

  • Build contexts are supplied as tar archives (e.g., from remote sources, CI pipelines, or user uploads).
  • The archive contents are not fully trusted or may be influenced by external actors.
  • Kaniko has access to docker credential helpers or other executables that can be abused if arbitrary files are written adjacent to them.

The issue manifests during tar extraction, before the build process completes.

Exploit preconditions

  • Attack surface: Kaniko build context ingestion (tar-based build contexts).
  • Required access: Ability to provide or modify the build context archive used by Kaniko (e.g., pushing a malicious context to a repository, altering CI artifacts, or man-in-the-middle on context delivery).
  • Trigger point: Submission of a crafted tar archive containing file names with .. components (such as ../ prefixes) that is then extracted by Kaniko.
  • Why exploitation is possible: The code uses filepath.Join(dest, cleanedName) to resolve extraction paths without subsequently enforcing that the resulting path remains within the dest directory, enabling directory traversal and writes outside the expected extraction root.

Why this happens

The underlying bug is a classic directory traversal issue in archive extraction.

Kaniko constructs extraction paths by joining the target directory with the file name from the tar entry using filepath.Join(dest, cleanedName), but does not verify that the resulting path is still beneath dest after normalization.

As described by CWE-22: Improper Limitation of a Pathname to a Restricted Directory, this pattern allows inputs containing .. components to escape the intended directory.

When combined with sensitive filesystem locations (such as directories containing credential helpers or configuration files), the arbitrary file write capability may be escalated into code execution within the executor process.

Potential impact

  • Arbitrary file creation or overwrite outside the intended build context directory.
  • Overwriting configuration files used by the build environment.
  • Planting or modifying helper binaries or scripts in search paths used by the executor.
  • Achieving code execution within the Kaniko executor process when combined with registry credential helpers or similar mechanisms.
  • Lateral movement or escalation within the CI/CD or Kubernetes environment, depending on surrounding controls.

General mitigation guidance

Effective mitigation focuses on enforcing strict path confinement during archive extraction and reducing the trust placed in build contexts:

  • Use canonical path resolution that verifies the final extraction path remains under the intended root directory before writing (e.g., secure join patterns).
  • Reject tar entries containing .., absolute paths, or other path components that could escape the extraction root.
  • Treat build contexts as untrusted inputs by default; avoid giving the executor unnecessary privileges, filesystem access, or sensitive helper binaries in the same directory tree.
  • Run the Kaniko executor with least privilege, using isolated work directories and avoiding shared volumes that contain secrets or executables.
  • Separate secrets and credential helpers from locations where user-controlled archives are unpacked to limit the impact of any traversal.

How teams detect issues like this

Organizations can detect and monitor for similar issues through multiple approaches:

  • Static analysis: Scan codebases for archive extraction routines that use filepath.Join (or equivalents) without subsequent checks that the resolved path is confined to a designated root. Flag patterns that do not normalize and validate paths after joining.
  • Code review: Pay special attention to tar/zip extraction logic, looking for use of entry names directly in filesystem operations and for missing checks against .. components, absolute paths, or symlink resolution.
  • Security testing: Include tests that feed crafted archives with traversal payloads into build and packaging tools, verifying they are rejected or safely contained.
  • Runtime monitoring: In sensitive environments, monitor for unexpected file writes outside designated build directories during Kaniko executions, using file integrity monitoring or container runtime auditing.
  • Automated review tools or custom linters can be configured to flag insecure archive extraction constructs early in development.

Sources

SourceLink
github.comgithub.com/chainguard-forks/kaniko/commit/a370e4b1f66e6e842b685c8f70ed507964c4b221
github.comgithub.com/chainguard-forks/kaniko/pull/326
github.comgithub.com/chainguard-forks/kaniko/security/advisories/GHSA-6rxq-q92g-4rmf
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-28406
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2443462
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-28406.json

Frequently asked

questions

It can be, depending on how Kaniko is integrated. If external users or services can supply or influence the build context archive (for example via source repositories, uploaded artifacts, or remote context URLs), an attacker may exploit the issue without direct access to the executor container.

The attacker must be able to control or tamper with the tar archive used as the build context. They typically do not need shell access to the Kaniko container itself, but do need influence over inputs consumed by the Kaniko build process.

The safest pattern is to perform secure path joining and validation for every archive entry: resolve the destination path, normalize it, and enforce that it remains under the intended extraction root before creating files or directories. Entries that violate this constraint should be rejected outright.

Treat all archive contents as untrusted data, use well-reviewed secure-join utilities or patterns, implement strict path validation and rejection rules for traversal attempts, and place sensitive files, secrets, and executables outside any directories where user-controlled archives are unpacked. Regular security reviews and tests focused on archive extraction logic help catch regressions early.

Find out what's already
exploitable in your codebase.