/

CVE-2026-33748

Severity:

HIGH RISK

(7.5)

Path Traversal in BuildKit Git Source Handling

CVE-2026-33748

Analyzed

Vulnerability type

Category:

Path Traversal / Directory Traversal

CWE:

CWE-22, CWE-59

Impact:

Unauthorized File System Access / Information Disclosure

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

BuildKit's handling of Git URLs with subdirectory components can allow builds to access files outside the checked-out repository root when subdir paths are resolved through symlinks.

In environments where untrusted Git URLs or subdir values are used, an attacker-controlled repository may cause a build to read sensitive files from the same mounted filesystem, potentially exposing secrets or internal configuration.

Affected context

The vulnerability occurs in BuildKit builds that:

  • Fetch build context from Git repositories using Git URLs with a subdir (subpath) component, and
  • Evaluate that subdir against a filesystem that may contain symlinks or indirect path segments.

Risk is most pronounced when build definitions (e.g., Dockerfiles) and Git URLs originate from untrusted or semi-trusted sources, and when the build worker's filesystem also hosts sensitive files on the same mount as the checkout.

Exploit preconditions

  • Attack surface: BuildKit daemon or build environment that accepts Git URLs with a subdir component.
  • Required access: Ability to influence or supply:
  • The Git repository content, including symlink layout; and/or
  • The Git URL used as build context, especially its subdir value.
  • Trigger point: A build is started that:
  • Uses a Git URL with a subdir component, and
  • Resolves that subdir into the build context before robust path normalization and restriction to the repository root.
  • Why exploitation is possible: Insufficient validation and canonicalization of the subdir path and symlink resolution allows path traversal outside the intended repository directory, while still remaining on the same mounted filesystem.

Why this happens

The core issue is incomplete enforcement of directory boundaries when resolving subdirectory components within Git-based build contexts.

BuildKit allows specifying a subdir in Git URLs to limit the build context to a specific folder; however, the logic responsible for resolving this subdir did not fully guard against symlink-based escapes or path traversal patterns that lead outside the repository root.

This maps primarily to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controllable path elements are insufficiently constrained, and secondarily to CWE-59: Improper Link Resolution Before File Access, because symlink resolution is not validated against a fixed root.

Conceptually, the unsafe pattern is: taking a user-influenced path component (subdir in Git URL) and combining it with the repository checkout path, then following filesystem links without re-checking that the final resolved path still lies within the intended repository boundary.

Potential impact

  • Read access to files outside the cloned Git repository but on the same filesystem mount
  • Exposure of build-time secrets, credentials, or configuration files stored adjacent to the checkout root
  • Disclosure of internal source code or scripts that were not meant to be part of the build context
  • Increased ability to map or infer the structure of the build worker's filesystem on the affected mount
  • Indirect assistance to further attacks if sensitive information is recovered (e.g., tokens, SSH keys)

General mitigation guidance

Effective mitigation focuses on constraining path resolution and reducing trust in external build inputs:

  • Enforce strict directory boundary checks: after resolving any subdir path (including symlinks), confirm that the canonical path remains within the Git checkout root.
  • Apply robust path normalization: normalize and canonicalize paths (resolving .., symlinks, and redundant separators) before any access decisions.
  • Treat Git URLs and subdir values as untrusted input: avoid depending on repository-controlled symlinks or complex subdir layouts for security controls.
  • Isolate build filesystem mounts: ensure sensitive files are not colocated on the same mount as untrusted build contexts, or run builds in minimally privileged, ephemeral workspaces.
  • Limit secret exposure: store secrets in dedicated, tightly scoped locations and use secret-injection mechanisms that do not rely on the general filesystem around the build context.
  • Prefer secure defaults: discourage or disable subdir usage from untrusted repositories when not strictly necessary, or require additional validation when such patterns are used.

How teams detect issues like this

Organizations can look for and detect similar issues with a combination of analysis and process controls:

  • Static analysis patterns:
  • Identify code paths where user- or configuration-controlled path segments (e.g., subdir parameters) are concatenated with base directories without subsequent canonicalization and boundary checks.
  • Flag logic that follows symlinks or uses generic filesystem traversal on paths derived from external inputs, especially in build- or packaging-related components.
  • Code review signals:
  • Review Git-context and build-context handling code for:
  • Any use of subdirectory selection, path joins, or symlink resolution.
  • Lack of explicit enforcement that final resolved paths remain under an expected root.
  • Pay attention to areas where repository contents (e.g., symlinks) influence which files are included in build contexts.
  • Policy and tooling:
  • Implement policy checks that restrict or log builds using Git URLs with subdir components, especially when the source is untrusted.
  • Use automated code review or SAST tools capable of modeling path manipulation and symlink resolution, and configure them with rules focused on directory traversal and link resolution weaknesses.
  • Monitor build logs and telemetry for unexpected file access patterns or failures when resolving subdirectories during Git-based builds.

Sources

SourceLink
docs.docker.comdocs.docker.com/build/concepts/context/#url-fragments
github.comgithub.com/moby/buildkit/releases/tag/v0.28.1
github.comgithub.com/moby/buildkit/security/advisories/GHSA-4vrq-3vrq-g6gg

Frequently asked

questions

It can be, depending on how BuildKit is exposed. If an attacker can remotely supply or influence Git URLs or the repositories used for builds, they may trigger the issue over a network interface that starts builds on their behalf.

The attacker typically must control or significantly influence either the Git repository content (including symlinks and directory structure) or the Git URL parameters (notably the subdir component) that BuildKit uses as build context.

From an implementation perspective, ensure that after resolving any subdir path and following symlinks, the resulting canonical path is validated to remain within the repository checkout root. Operationally, isolate build contexts on dedicated mounts and avoid colocating sensitive files with untrusted build workspaces.

Treat all externally influenced paths as untrusted, normalize and canonicalize them, enforce strict root-directory boundaries after symlink and .. resolution, and design build systems so that untrusted code and sensitive assets do not share the same filesystem areas or mounts. Additionally, establish code review and automated checks specifically targeting path traversal and symlink resolution logic.

Find out what's already
exploitable in your codebase.