Summary
A path traversal issue in BuildKit allows a malicious custom frontend to craft API requests that write files outside the BuildKit state directory associated with the build execution context.
If a build uses an untrusted frontend specified via #syntax or --build-arg BUILDKIT_SYNTAX, this behavior can be abused to overwrite or create files on the host or in adjacent directories, breaking build isolation and integrity guarantees.
Affected context
This vulnerability occurs in BuildKit environments that:
- Allow use of custom or third-party BuildKit frontends, and
- Accept frontend selection via
#syntaxdirectives in Dockerfiles or the--build-arg BUILDKIT_SYNTAXoption, and - Do not fully trust the selected frontend image.
The issue manifests when the frontend crafts specific API messages that cause BuildKit to resolve and write files outside the intended state directory used for a given build context, potentially impacting host or neighboring directories depending on deployment.
Exploit preconditions
- Attack surface: Build workloads running through BuildKit where frontend selection is user-controlled or influenced by untrusted sources.
- Required access: Ability to choose or control the BuildKit frontend image via
#syntaxin the Dockerfile or--build-arg BUILDKIT_SYNTAXat build time (e.g., commit access, CI configuration control, or build command execution). - Trigger point: Execution of a crafted frontend that issues specially formed API calls directing BuildKit to place files at paths that escape the state directory.
- Why exploitation is possible: BuildKit did not sufficiently constrain or normalize file paths derived from frontend API messages, allowing directory traversal outside the designated state directory for the build execution context.
Why this happens
The underlying issue is inadequate validation and normalization of file paths derived from frontend-controlled input within BuildKit's internal APIs.
A custom frontend can specify paths that include traversal sequences or otherwise manipulate how BuildKit resolves output locations, causing writes to escape the intended state directory.
This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'), where insufficient enforcement of directory boundaries permits access to filesystem locations that should remain out of scope for the component.
Potential impact
- A malicious frontend may write or overwrite files outside the BuildKit state directory used for the build.
- Build isolation guarantees can be weakened, potentially affecting host files or shared volumes depending on the deployment configuration.
- Build outputs or intermediate artifacts can be tampered with, impacting supply-chain integrity.
- Sensitive configuration files or scripts used by the build environment may be modified, enabling follow-on compromise or persistence in CI/CD systems.
General mitigation guidance
Effective mitigation focuses on reducing trust in arbitrary frontends and tightening filesystem boundaries:
- Prefer vetted, well-known frontend images (such as maintained official Docker or BuildKit frontends) and avoid unreviewed or community-provided images in sensitive environments.
- Restrict who can modify Dockerfiles,
#syntaxdirectives, and CI/CD build configurations to limit exposure to untrusted frontends. - Enforce policy that disallows or centrally controls the use of
--build-arg BUILDKIT_SYNTAXin automated pipelines. - Run BuildKit builds with least-privilege filesystem access, limiting the host paths and volumes the builder can influence, and separating build state from critical host directories.
- Apply configuration hardening around build executors to treat frontend input as untrusted and avoid giving builds unnecessary access to host resources.
How teams detect issues like this
Organizations can detect and monitor for this class of issue through:
- Static review of Dockerfiles and build scripts for unapproved
#syntaxdirectives orBUILDKIT_SYNTAXarguments, enforced via code review policies or pre-commit hooks. - CI/CD policy checks that allow only an approved list of frontend images and block builds that deviate from those lists.
- Runtime logging and monitoring of BuildKit behavior to flag unusual file writes outside expected state directories or into sensitive filesystem paths.
- Use of security scanning and analysis tools that understand BuildKit configurations and can highlight potentially dangerous frontend selection or filesystem exposure patterns.

