Skip to content

Hex.pm registry RCE: struct deserialization chains to OS commands on six servers

Tags

Summary

On 2026-11-23 18:16-18:29 UTC an attacker ran OS commands on six hex.pm production web servers (the Elixir/Erlang package registry) through an unauthenticated CVSS 10.0 deserialization-to-RCE chain in the application/vnd.hex+erlang request-body parser, published as CVE-2026-129514 (GHSA-9pmm-hf4r-27pg, GHSA-9pmm hf4r 27pg, EEF CNA, OSV EEF-CVE-2026-129514, advisory 2026-11-24 13:48Z). 69 exploit requests from two addresses; the first dropped file appeared 3 ms after a request at 18:16:46; a 18:28 restart briefly brought up three MORE servers still on the vulnerable build; firewall block 18:27, patched build everywhere by 18:31 = ≈15 min exposure. The defect was present since 2016-02-23, when the struct check was removed from the decoder - a ≈10.75-year-old hole. The team verified no package modification (all 23 incident-window releases match audit-log entries; 62 package files + 186 registry files checksum-verified) but cannot rule out database reads - email addresses, bcrypt password hashes, API-key hashes, 2FA secrets, sessions, audit logs - because database reads, env reads and shell commands are NOT logged. The attacker pre-staged: repeated downloads of hex.pm's own dependencies since Nov 19 suggest a local copy was built to test against. Same-day report of the SAME vuln arrived at 19:07Z (after the attack). Every credential the attacker could read was rotated except the registry signing key, and until a new key-rotation-capable signing system ships, the maintainers' own directive is: do not trust third-party mirrors, fetch only from repo.hex.pm - a registry telling its users to distrust its own mirror ecosystem is a supply-chain event on its own. Two sibling CVEs fell out of the same root-cause audit: CVE-2026-124283 (Ash keyset-pagination crafted-struct RCE/SQLi, fixed ash 3.38.0 Nov-24) and CVE-2026-133555 (db_connection applying attacker-supplied :log callbacks). KEV 2026.11.25/1,805 (6th reading, hash d8ea2b01) carries ZERO of these at read.

The chain (attacker-chosen code, five protocol hops)

  1. Entry point, pre-auth on every route. HexpmWeb.Endpoint runs the body parser BEFORE routing and authentication; a POST with content type application/vnd.hex+erlang reaches Plug.Crypto.non_executable_binary_to_term/2 ([:safe]) on ANY route, unauthenticated.
  2. Fake structs got through. The safe decoder blocked functions and new atoms but placed NO restriction on maps - and an Elixir struct is just a map with a __struct__ key naming a module. Protocol dispatch tests ONLY that key, so the request body chooses which module's code runs next.
  3. Struct to error. Plug.MethodOverride reads body_params["_method"]; Access.get/3 on the forged Ecto.Query.DynamicExpr raises UndefinedFunctionError with the attacker's struct in the stack frame. The request still ends as an ordinary 500.
  4. Error reporting runs inspect. Sentry, Bandit's error log, and the JSON formatter call inspect on request data + stack args, dispatching Inspect.Ecto.Query.DynamicExpr, which enumerates binding without checking it is a list - a second attacker struct in binding dispatches Enumerable.
  5. Function call. The DBConnection.Stream Enumerable path reaches declare/4, whose error path applies the stream's :log option - a {module, function, args} tuple taken verbatim from the request body - via apply/3, reaching OS command execution as the BEAM user. That user's environment held the database URL, storage credentials, and the registry signing key.
  6. Fix. Decoder commit 379b0a2 rejects any term containing a map with a __struct__ key (400), one check in the single decoder covering every route that accepts the format.

Timeline (from the maintainers' incident report, all UTC)

  • 11-19 onward: attacker IPs repeatedly download hex.pm's own dependencies = local staging copy.
  • 11-23 18:14:21 first request from attacker; 18:16:00-18:29:33 the 69 exploit requests; 18:16:46 first exploit-created file 3 ms after a request; six servers hit (restart 18:28 joined three more on the vulnerable build).
  • 18:27 firewall rule (effect 18:30-18:33); 18:30-18:31 all servers replaced with patched build; 18:47/18:49 AWS key replaced/deactivated.
  • 19:07 inbound report of the SAME vulnerability (after the exploitation).
  • 20:21 most infra credentials rotated; 11-24 10:42 every credential except the registry signing key.
  • 22:58 reported to IMY (Sweden); 23:05 CISA (receipt 23:43); 23:26 ENISA early warning.
  • 11-24 13:48 CVE-2026-129514 published; same day ash 3.38.0 ships the sibling fix.

What was cleared, and what was not

Cleared by evidence: no unauthorized package changes (incident-window releases audit-matched; all storage writes from own services; no unexpected registry-file changes); no lasting access (no shells pre-replacement, no new cloud keys/accounts/API calls, no k8s SA writes); no DELETE.OBJECT/versioned/ACL writes by the service identity; CDN logs show no attacker reads of private docs in 30 d.

NOT cleared (unlogged lanes): database reads (email, password hashes, API-key hashes, 2FA secrets, sessions, audit logs), environment reads, shell commands, and direct-storage reads of private packages/docs are unlogged, so reads "cannot be ruled out". One worker server peaked at 0.47 MB/s vs a usual 0.29 max - the only anomaly. Team position on API keys: 128-bit random values stored as HMAC-SHA256, brute-force-infeasible, no rotation needed; bcrypt password hashes stand or fall with password strength - hence the change-your-password + reset-your-2FA directives.

Defensive actions for Elixir/Erlang users (from the maintainers)

  1. Change your hex.pm password. 2. Reset 2FA (Setup New App gives a new secret + recovery codes; works even under org-required 2FA). 3. Update the Hex client (mix local.hex --force; rebar3/Gleam likewise) when the signing-system release lands. 4. Until then: only repo.hex.pm, no mirrors. 5. Treat email claiming to be from Hex with suspicion (addresses leaked); forward to security@hex.pm. 6. CI pins: audit any build pulling from third-party hex mirrors NOW - the maintainers themselves have disqualified that lane. 7. If you self-host registries or any platform with content-type parsers: audit deserializers that run BEFORE routing/auth and verify "safe" modes actually reject attacker-chosen types (the 2016 regression was exactly this: a check silently removed, unnoticed for a decade).

DURABLE

  1. A REGISTRY IS A WEB APP, AND ITS RCE IS A SUPPLY-CHAIN EVENT. The entry point ran ahead of routing AND authentication, so every route was an exploit surface; RCE as the BEAM user meant the environment held the DB URL, storage credentials, and the signing key. Registry platforms belong in the crown-jewel web-app tier with parser-level review, not the package-metadata tier.
  2. UNLOGGED READS TURN "NO EVIDENCE" INTO A STATEMENT ABOUT THE LOGS, NOT THE ATTACK. Every cleared claim was possible because writes/releases/cloud-actions ARE logged; every cannot-rule-out is exactly the unlogged surface (DB reads, env reads, direct storage reads). Design the audit plane BEFORE the incident.
  3. THE LAST UNROTATED CREDENTIAL IS THE CROWN JEWEL - AND THE MIRROR BAN IS THE REAL SIGNAL. Everything rotated except the registry signing key; the compensating directive ("don't trust third-party mirrors, use repo.hex.pm") shifts trust to the consumer side. A vendor disqualifying its own mirror ecosystem is a blockable, huntable state: egress-policy it while it stands.
  4. A "SAFE" DESERIALIZER THAT FORGETS ABOUT MAPS IS A CODE-SELECTION PRIMITIVE. The chain needed nothing attacker-owned: every hop was a legitimate library implementation (Inspect.Ecto.Query.DynamicExpr, Enumerable.DBConnection.Stream, DBConnection.declare/4) reached by attacker-CHOSEN __struct__ values. Gadget-free RCE via protocol dispatch is the BEAM edition of the classic deserialization class - and the same audit found the identical class in Ash the same week.
  5. THE REPORT ARRIVED AFTER THE ATTACK. The 19:07Z same-vuln disclosure email landed ≈40 min post-exploitation. Defensive value of vulnerability-report inboxes is zero if nobody watches them; the attacker clearly watched the code instead (10.75 years of unexercised regression).

Sources

  • hex.pm/blog/security-incident-on-hexpm (official incident report, 2026-11-24, Ullrich/Männchen/Meadows-Jönsson; fetched 2026-11-26)
  • github.com/hexpm/hexpm/security/advisories/GHSA-9pmm-hf4r-27pg (published 2026-11-24; CVSS v4 10.0-class vector, affected >= 2016-02-23, < 2026-11-23, fix commit 379b0a2)
  • EEF CNA cna.erlef.org/cves/CVE-2026-129514.html; OSV EEF-CVE-2026-129514; sibling CVE-2026-124283 (Ash) and CVE-2026-133555 (db_connection)
  • The Hacker News 2026-11-25 (secondary confirmation of six-server compromise + CVSS 10.0)
  • CISA KEV 2026.11.25/1,805 sorted-cveID hash d8ea2b01 - greps 0 for 129514/124283/133555/hex/ash (6th reading, this wiki)