Summary
Hex ecosystem API client modules in hex_core, hex, and rebar3 perform unsafe deserialization of untrusted server responses and can consume excessive resources when processing crafted data.
An attacker who can control or intercept Hex registry responses may trigger object injection or force excessive allocation in client tools, potentially leading to denial of service or unexpected behavior during dependency and package operations.
Affected context
This vulnerability arises in Erlang and Elixir projects that use:
hex_core(viahex_core:request/4)hex(viamix_hex_api:request/4)rebar3(viar3_hex_api:request/4)
when communicating with Hex registries or proxy services.
It becomes relevant in environments where the client trusts remote API responses for package metadata, tarballs, and other payloads without sufficiently constraining what is deserialized or how much data can be allocated in-memory while handling those responses.
Exploit preconditions
- Attack surface: Network-facing Hex API clients (hex_core, mix hex, rebar3) when they initiate HTTP(S) requests to a registry or mirror.
- Required access: Ability to operate a malicious registry/mirror, compromise DNS or TLS termination, perform man-in-the-middle, or otherwise control HTTP responses to the affected
*_api:request/4routines. - Trigger point: Processing the HTTP response body and deserializing received content into in-memory structures during dependency resolution, package publication, or metadata retrieval.
- Why exploitation is possible:
- Response data is treated as trusted and deserialized with logic that can create complex or deeply nested objects (CWE-502).
- There are insufficient limits on size, depth, or complexity of processed data, enabling excessive memory allocation or CPU consumption (CWE-400).
Why this happens
The core issue is that the Hex API client modules implement deserialization of remote data in a way that:
- Assumes the registry is honest and does not robustly constrain the structure or volume of data being parsed.
- Allows remote input to drive the shape and complexity of in-memory terms and possibly invoke code paths for object-like structures.
This pattern corresponds to:
- CWE-502 (Deserialization of Untrusted Data): Untrusted responses from a remote service are parsed into live data structures without sufficient validation or restriction on what can be instantiated.
- CWE-400 (Uncontrolled Resource Consumption): The parsing and allocation routines do not adequately bound memory or CPU usage, so a crafted response can cause excessive allocation and processing.
In abstract terms, the bug is an over-trusting deserialization layer combined with missing resource guards around network-derived data.
Potential impact
- Client-side denial of service due to high memory usage or CPU consumption during package operations.
- Degradation or outage of CI/CD pipelines that rely on hex or rebar3 for dependency management.
- Disruption of developer tooling, causing build failures or unresponsive shells when interacting with the package registry.
- Creation of unexpected or malformed in-memory structures that could interfere with downstream logic and error handling.
General mitigation guidance
Effective mitigation focuses on constraining how remote data is interpreted and how many resources it can consume:
- Prefer data formats and parsers that treat registry responses as plain data, not as executable or object-bearing content.
- Enforce strict validation and schema checks on all deserialized responses, rejecting overly complex or unexpected structures.
- Introduce clear limits on payload size, nesting depth, and number of elements processed from remote responses to prevent excessive allocation.
- Apply defensive coding patterns in HTTP client layers, such as timeouts, streaming where appropriate, and graceful handling of partial or truncated data.
- Isolate network-driven processing in components running with minimal privileges so that failures or spikes have limited blast radius.
How teams detect issues like this
To detect and manage similar vulnerabilities:
- Use static analysis or linters to flag deserialization logic that operates directly on network data without validation or size checks.
- During code review, pay particular attention to HTTP client wrappers (
*_api:request/4) and common response-handling utilities, looking for: - Trust of remote registry data without schema enforcement.
- Absence of size, depth, or iteration limits on parsed collections.
- Incorporate fuzzing of registry response handlers to discover paths that cause excessive memory or CPU usage.
- Establish security policies that require safe parsing APIs, mandatory resource limits, and clear error handling for malformed or oversized responses.

