Summary
A path traversal flaw in the Elixir Hexpm.Store.Local module allows crafted relative paths to escape the intended storage directory when accessing or modifying files.
In self-hosted HexPM deployments using the Local Storage backend, an attacker who can influence object keys or storage paths may read, overwrite, or delete files outside the configured storage root.
Affected context
The vulnerability occurs in self-hosted HexPM instances that use the Local Storage backend implemented by Elixir.Hexpm.Store.Local.
The affected routines (get/3, put/4, delete/2, delete_many/2) operate on filesystem paths derived from user-controlled or externally influenced identifiers.
When these identifiers are not normalized or safely joined against a fixed root, directory traversal sequences (such as ../) can allow operations to break out of the intended storage directory.
The hosted hex.pm service itself is not impacted; only deployments that explicitly configure and run the vulnerable local storage module are exposed.
Exploit preconditions
- Attack surface: Application interfaces that ultimately call
Elixir.Hexpm.Store.Local.get/3,put/4,delete/2, ordelete_many/2with path-like inputs (e.g., package names, versions, or file keys). - Required access: Ability to create, upload, request, or delete stored objects such that the attacker controls or significantly influences the key or path segments.
- Trigger point: Any file operation where the backend converts the supplied key into a filesystem path without robust normalization and enforcement of a fixed base directory.
- Why exploitation is possible: The code constructs filesystem paths directly from attacker-influenced values without sufficiently constraining them to remain within the configured storage root, enabling relative path traversal sequences to reach unintended directories.
Why this happens
This issue stems from improper validation and normalization of file paths derived from untrusted input in the Elixir.Hexpm.Store.Local module.
The backend treats user-influenced keys as trusted path segments and concatenates them with a base directory, but does not consistently canonicalize the resulting path or verify that it stays within the intended storage root.
As described by CWE-22: Improper Limitation of a Pathname to a Restricted Directory, the application fails to restrict paths to a controlled directory, allowing traversal via relative components (e.g., ..) or similar constructs.
Abstractly, this pattern appears whenever storage or caching layers map logical keys to filesystem paths without using safe path-joining mechanisms and without a final check that the resolved absolute path is still under an allowed directory.
Potential impact
- Read access to arbitrary files that the HexPM process user can access on the underlying server.
- Overwriting or corrupting files outside the intended storage directory, potentially impacting application configuration or data integrity.
- Deletion of files outside the storage root, which could lead to denial of service or data loss.
- Indirect escalation of impact if sensitive credentials, API keys, or configuration files are exposed through unauthorized reads.
General mitigation guidance
Effective mitigation focuses on strictly confining all filesystem operations to a well-defined storage root and treating all path components as untrusted:
- Use robust, platform-aware path-joining helpers that construct paths from a fixed base directory and user-supplied segments without string concatenation.
- Normalize and canonicalize paths (e.g., resolving
.and..) and enforce a post-check that the resolved absolute path is a descendant of the configured storage root before performing any file operation. - Reject or sanitize any key or path segment containing directory traversal markers, path separators, or other unexpected characters according to a strict allowlist.
- Run the HexPM process with the least privileges necessary, ensuring the service account only has access to directories intended for storage.
- Consider isolating local storage into a dedicated directory or filesystem partition with minimal access to the rest of the system.
How teams detect issues like this
Detection typically combines code-level review with behavioral monitoring:
- Use static analysis or code review to identify any file operations where user-controlled values are concatenated into paths without normalization and explicit base-directory checks.
- Look for patterns such as direct string concatenation when building paths and absence of checks to ensure the resolved path remains within a configured root directory.
- Implement security-focused tests or fuzzing that attempt to access files via
../sequences or similar traversal patterns through the application's public interfaces. - Monitor server logs and application telemetry for suspicious access patterns, such as requests targeting unexpected directories or repeated attempts to reach sensitive files (e.g., configuration or system files).

