Am I affected?
Description
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal') vulnerability in gleam-lang gleam allows a malicious package publisher to delete a directory outside the project's build directory when a developer builds a project.
A Hex package release's metadata carries an app field with the release's OTP application name. Gleam reads this field from the hex.pm release API when it downloads dependencies and uses it as the package's build directory name without validating it (hex_manifest_package in compiler-cli/src/dependencies.rs, ProjectPaths::build_directory_for_package). When a dependency fails to compile, Gleam deletes that directory with remove_dir_all. hex.pm didn't restrict the field to a directory name before 2026-10-12, so a publisher could set it to a value such as ../../../../target or an absolute path. When a project depends on such a release directly or transitively and the release fails to compile, gleam build, gleam check, gleam run, gleam test or gleam export deletes the directory the name resolves to. For a pure Gleam package no publisher code runs.
This issue affects gleam: from 0.32.4 before 1.19.2.
Technical analysis
hex_manifest_package(compiler-cli/src/dependencies.rs) sets the manifest package'sotp_apptometa.appfromGET packages/<name>/releases/<version>without validation. hex.pm doesn't restrict this field to a directory name. The signed registry record's dependencyapplabel is decoded but never used as a path.ManifestPackage::application_name(compiler-core/src/manifest.rs) returnsotp_appwhen it is set.ProjectPaths::build_directory_for_package(compiler-core/src/paths.rs) joins the application name onto the target's build directory. A..component escapes the build directory, and an absolute path replaces the whole path.- When a dependency fails to compile,
ProjectCompiler::load_cache_or_compile_package(compiler-core/src/build/project_compiler.rs) callsdelete_directoryon that path, which runsstd::fs::remove_dir_all(compiler-cli/src/fs.rs). - The manifest built by
download_dependenciesis passed tobuild::mainin the same run, so the name reaches compilation without amanifest.tomlround trip.otp_appis validated against^[a-z][a-z0-9_]*$only whenmanifest.tomlis read from disk (commit 2dc0467, first released in v1.16.0), which rejects a stored malicious manifest on a later run but not the first run that produces it. - Extraction uses the package name, which hex.pm validates, so the effect is a directory delete without an overwrite. For a package with
build_tools = ["gleam"]no publisher code runs, so source that fails to compile or a malformedgleam.tomltriggers the delete. For rebar3 and Mix dependencies, publisher code runs anyway.
Proof of concept
Not reproduced end to end, because Gleam only uses hex.pm and has no setting for another repository. A unit test calling ProjectPaths::build_directory_for_package with the application names ../../../../canary and an absolute path computed build directories outside the project, and std::fs::remove_dir_all, the call behind delete_directory, deleted a canary directory placed there. The chain from meta.app to the delete was established by reading the source.
Weaknesses & attack patterns
Weakness
CWE-22
·
Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
in catalog →
MITRE ↗
Attack patterns
CAPEC-126
·
Path Traversal
MITRE ↗
A publisher of a package in a project's dependency tree can make a Gleam build delete a directory that the developer's account can write, outside the project's build directory or anywhere on the filesystem when the application name is an absolute path. For a pure Gleam package this happens without running any of the publisher's code. Developers and CI jobs that build projects with Gleam are affected; gleam deps download alone isn't.
Affected — Gleam
modules · source files · routines
Affected — ghcr.io / gleam-lang/gleam Container registry ↗
modules · source files · routines
Affected — GitHub / gleam-lang/gleam Repository ↗
modules · source files · routines
Configurations
Affects projects whose dependency tree, directly or transitively, contains a hex.pm package release whose OTP application name is a path, when the project is built with gleam build, gleam check, gleam run, gleam test or gleam export. gleam deps download alone doesn't reach the delete. Gleam only uses hex.pm, which rejects such application names when a release is published since 2026-10-12, so only releases published before then can have one.
Solutions
Upgrade Gleam to 1.19.2 or later. Gleam then rejects a hex.pm release whose OTP application name, or the application name it gives a dependency, isn't a lowercase letter followed by lowercase letters, digits and _.
References
Credits
CVSS breakdown
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:A/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N