Summary
An improper path validation issue in the Gleam compiler's git dependency handling allows dependency names from configuration files to influence filesystem paths outside the intended dependency directory.
A malicious direct or transitive git dependency can craft names that traverse directories or use absolute paths, enabling deletion and overwriting of arbitrary paths during dependency download and resolution, which can cause data loss and, in some environments, lead to code execution.
Affected context
This vulnerability appears when Gleam projects use git-based dependencies whose names are derived from gleam.toml and manifest.toml.
During gleam deps download and similar dependency resolution stages, the compiler computes filesystem paths for these dependencies without sufficiently constraining them to the dedicated dependency directory.
Installations where build tooling runs with access to sensitive directories (such as user home directories, shared workspaces, or CI build agents) are particularly exposed, as crafted dependency names can affect files and directories outside the normal dependency tree.
Exploit preconditions
- Attack surface: The Gleam dependency resolution and download phase, typically executed via commands like
gleam deps download. - Required access: Ability to introduce or influence a git dependency entry in
gleam.tomlormanifest.toml, either as a direct dependency in the project or as a transitive dependency in a referenced repository. - Trigger point: Running Gleam tooling that resolves and downloads git dependencies, which computes and uses the derived paths for filesystem operations such as directory deletion and creation.
- Why exploitation is possible: Dependency names are incorporated into filesystem paths without robust normalization, confinement, or rejection of traversal sequences (e.g.
../) and absolute paths, allowing attacker-controlled values to escape the intended dependency directory.
Why this happens
The core issue is insufficient validation and confinement of filesystem paths constructed from partially untrusted configuration data.
In this case, dependency names from gleam.toml and manifest.toml are treated as safe components for building local directories used during git dependency resolution.
Without rigorous normalization, rejection of traversal and absolute paths, or enforcement that the resulting path remains within a designated root, these derived paths can point outside the expected dependency tree.
This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controlled or configuration-controlled path elements are allowed to escape a presumed sandbox and affect arbitrary locations on the filesystem.
Potential impact
- Deletion of arbitrary directories and their contents outside the intended dependency directory.
- Overwriting of arbitrary directories or files reachable by the Gleam process.
- Disruption of build environments and potential corruption of project repositories.
- In some environments, execution of attacker-controlled code by overwriting:
- Git hooks in repositories
- Shell startup or profile configuration files
- Other scripts that are later executed by users or automation.
- Persistence of malicious changes across builds or developer sessions.
General mitigation guidance
Effective mitigation focuses on constraining how filesystem paths are derived and ensuring that dependency-related operations cannot escape a dedicated directory.
Common defensive patterns include:
- Strictly normalizing and validating all paths derived from configuration, rejecting any input that resolves outside the intended dependency root.
- Disallowing path elements that include traversal sequences (
..), leading separators, or constructs that create absolute paths, rather than attempting to silently sanitize them. - Constructing dependency paths using safe path-joining utilities and post-join checks that enforce containment within a known base directory.
- Treating dependency metadata (names, URLs, identifiers) as untrusted and subjecting them to the same trust-reduction and validation rules as external input.
- Running build and dependency tooling under least-privilege accounts with restricted write access, so even if path handling fails, the process cannot modify sensitive system locations.
Applying these patterns helps ensure that dependency resolution is effectively sandboxed to a controlled directory structure.
How teams detect issues like this
Organizations can identify and monitor for this class of issue using multiple complementary strategies:
- Static analysis and code scanning:
- Rules that flag manual string concatenation for filesystem paths involving configuration or dependency metadata.
- Checks that detect filesystem operations (such as delete, create, move) using paths that are not validated or normalized against a fixed base directory.
- Code review practices:
- Reviewing dependency management and build tooling code for assumptions that configuration-derived identifiers are inherently safe.
- Verifying that any path derived from configuration is subject to a "stay within this root" policy with explicit failure on violation.
- Policy enforcement:
- CI pipeline checks that prevent merging changes introducing unsafe path handling in build or dependency-related modules.
- Optional use of security-focused linters or SAST tools configured with rules specific to path traversal in build tools.
- Runtime/operational monitoring:
- In sensitive environments, using file integrity monitoring or audit logs to observe unexpected directory deletions or modifications during dependency resolution phases.

