Hex.pm Registry RCE, Exploited in the Wild (CVE-2026-129514)
An unauthenticated Erlang term body let an attacker run commands on six Hex.pm servers; the registry patched it and rotated credentials.
TL;DR
- An attacker ran operating-system commands on six Hex.pm servers on 2026-11-23 through a crafted Erlang term request body. The registry disclosed the incident on 2026-11-24.
- Self-hosted copies of the hexpm server application are affected until they deploy fix commit
379b0a2. The Hex client is not affected, and Hex.pm found no modified package. - The CVE record rates CVE-2026-129514 at CVSS v4.0 10.0 Critical with exploit maturity Attacked. The CVE is not in CISA KEV as of 2026-11-25.
- Deploy the fix, restart every node, and rotate every credential the servers could read. Hex.pm users should change their password and reset two-factor authentication.
Am I affected?
You are exposed when you operate the hexpm server application at a commit that predates the fix, and its endpoint still parses Erlang term request bodies before authentication.
All of these conditions must hold:
- You run the hexpm web application yourself. Using the Hex client against hex.pm does not expose your machines to this flaw.
- Your deployment is built from a commit before
379b0a2, which landed on 2026-11-23 at 18:26 UTC. - The endpoint accepts
application/vnd.hex+erlangrequest bodies before routing and authentication. The upstream endpoint does. A reverse proxy that rejects that content type removes the path.
If you only consume packages from hex.pm, your account data may be in scope but your machines are not. Hex.pm says database reads were not logged, so it cannot rule out that the attacker read account records.
| Deployment | Affected versions | Fixed version |
|---|---|---|
| Hosted hex.pm | Every request before 2026-11-23 18:31 UTC | Patched in place; there is no version to install |
| Self-hosted hexpm server | Commits before 379b0a2 |
379b0a2 or later |
Hex client (mix hex, rebar3, Gleam) |
None | Not affected |
The hexpm application has no release version string to read. Check the source commit your build came from:
git -C /srv/hexpm log -1 --format='%H %ci'
git -C /srv/hexpm merge-base --is-ancestor 379b0a29bcc95164249f38ad7d772a37a8ff9533 HEAD \
&& echo patched || echo not-patched
Check the decoder itself when you cannot read the build commit:
grep -n 'defp struct?' lib/hexpm_web/erlang_format.ex
No output means the recursive struct rejection is absent and the deployment is vulnerable. A match means the fix is present.
How do I fix it?
Deploy commit 379b0a2 or a later commit of the hexpm repository, then restart every web, worker and job node so no old build keeps serving requests.
- Fetch the fix and deploy it with your normal release process:
git -C /srv/hexpm fetch origin
git -C /srv/hexpm checkout 379b0a29bcc95164249f38ad7d772a37a8ff9533
- Rebuild the release and restart every node. Hex.pm brought all of its web, worker and job servers up from the patched build between 18:30 and 18:31 UTC on 2026-11-23.
- Confirm the running code carries the fix with the
grepcommand in "Am I affected?". - Rotate every credential the service account could read: object storage, CDN, email and database credentials, and the keys that sign sessions and access tokens. Hex.pm rotated most of them within two hours and the database password the next day.
- Invalidate sessions and access tokens. Rotating the signing keys logs every user out, which is the intended effect after a server compromise.
- Rotate the registry signing key when your replacement system supports key rotation. Hex.pm had not rotated that key when it published the incident report.
A reverse proxy can reject application/vnd.hex+erlang bodies as an interim control. That control breaks Hex clients, which send Erlang term bodies for dependency operations, so it only fits an internal registry whose clients use JSON. It does not repair the decoder, and it does nothing for a request that reaches the application directly.
If you have a hex.pm account, take the vendor's account steps:
- Change your password at
https://hex.pm/dashboard/security. - Reset two-factor authentication and store the new recovery codes.
- Sign the clients in again with
mix hex.user authorrebar3 hex user auth. - Update the Hex client when the release with the new signing system ships, and fetch packages only from
repo.hex.pmuntil then.
What is the root cause?
The endpoint decoded unauthenticated request bodies in the Erlang external term format. Its decoder blocked functions and new atoms, but accepted maps carrying a __struct__ key. A client could therefore choose any loaded Elixir struct as its request parameters.
The parser runs in the endpoint before routing and authentication. Its parse/5 clause matched any application/vnd.hex+ subtype and passed the body to the format decoder:
def parse(%Conn{} = conn, "application", "vnd.hex+" <> format, _headers, opts)
when format in @formats do
decoder = get_decoder(format, opts)
conn
|> Conn.read_body(opts)
|> decode(decoder)
end
The Erlang decoder called Plug.Crypto.non_executable_binary_to_term/2 with [:safe] and returned the term without inspecting its shape:
def decode(binary) do
term = Plug.Crypto.non_executable_binary_to_term(binary, [:safe])
{:ok, term}
rescue
ArgumentError ->
{:error, "bad binary_to_term"}
end
The [:safe] option rejects functions and atoms that do not already exist. It does not reject maps. An Elixir struct is a map with a __struct__ key naming a module, so a crafted map decodes into a value that the runtime treats as a real struct. Elixir protocol dispatch reads that key, so the client chooses which Inspect and Enumerable implementations run when the application logs or enumerates the value.
The safety check existed once. Commit ab1bbce removed it on 2016-02-23 under the message "Fix for some bad requests", which is why the CVE record dates the affected range from that day.
How is it exploited?
The attack turned one unauthenticated POST into an operating-system command by chaining the request parameters through error reporting and two database libraries, without ever reaching an application route.
- The attacker sends a POST to any path with
Content-Type: application/vnd.hex+erlang. The endpoint parser runs before routing and authentication, so every route reaches it. - The body is an Erlang external term containing a map with a
__struct__key. The decoder accepts it and the parser returns it as the request's body parameters. Plug.MethodOverridereadsbody_params["_method"]. On a struct that access callsfetch/2on the module named in__struct__. That module has no such function, so the request raisesUndefinedFunctionErrorwith the attacker's struct in the stack trace.- Sentry, Bandit's error logging and the JSON log formatter call
inspecton request data and stack-frame arguments.Inspectdispatches to the module named in__struct__, and the attacker choosesEcto.Query.DynamicExpr. - That
Inspectimplementation enumerates thebindingfield without checking that it is a list. ADBConnection.Streamstruct placed in that field dispatches itsEnumerableimplementation. DBConnection.reduce/3callsdeclare/4. Query encoding fails before a connection is checked out, but the error path still runs the stream's:logoption.- The
:logoption is a{module, function, args}tuple taken from the request. DBConnection applies it with the log entry prepended, so the attacker's function runs inside the BEAM and reaches an operating-system command as the service user.
The vendor published this chain after the attack. No standalone exploit program is known.
How does the attack flow?
One unauthenticated Erlang term body reaches a decoder that accepts fake structs. Protocol dispatch on the __struct__ key then carries the value through error reporting into a database library that applies an attacker-chosen function.
application/vnd.hex+erlang"] --> B["Decoder accepts a map
with __struct__"] B --> C["Params become a fake struct"] C --> D["MethodOverride raises
UndefinedFunctionError"] D --> E["inspect dispatches to
Ecto.Query.DynamicExpr"] E --> F["DBConnection.Stream runs
the request's :log tuple"] F --> G["OS command as the
BEAM service user"]
What can an attacker do?
An attacker who reaches the decoder can run operating-system commands as the user that runs the registry, which gives access to the credentials and data that user can read.
Every condition from "Am I affected?" still applies. The service must expose the hexpm endpoint with the vulnerable parser, and the request must reach it. The attacker needs no account, no session and no user interaction.
On hex.pm, the vendor's investigation found commands executed on six web servers. The attacker could read the credentials those servers used, including storage, CDN, email and database credentials and the keys that sign sessions and access tokens.
The database holds email addresses, bcrypt password hashes, HMAC hashes of API keys, two-factor secrets, sessions and audit logs. Database reads were not logged, so the vendor cannot rule out that the attacker read those records.
Package integrity is a separate question. Hex.pm compared every database table against a copy taken two minutes before the first exploit request. The 23 releases published during the attack match the audit log, no older release was changed, and the package and registry files written that evening match the database records. The vendor found no unexpected file in package storage.
The vendor found no shells, no new cloud keys and no writes by its Kubernetes service accounts. Reads of private packages in the period came from its own servers and coincide with releases their organisations published at the time. A read from a compromised server would look the same, and reads of private documentation are not logged, so the vendor says it cannot fully rule one out.
Why does the fix work?
The fix rejects any decoded term that contains a map with a __struct__ key, at any depth. A client can no longer place a real struct in the request parameters.
def decode(binary) do
term = Plug.Crypto.non_executable_binary_to_term(binary, [:safe])
- {:ok, term}
+
+ if struct?(term) do
+ {:error, "bad binary_to_term"}
+ else
+ {:ok, term}
+ end
rescue
ArgumentError ->
{:error, "bad binary_to_term"}
end
+
+ # A decoded map with a :__struct__ key is dispatched to that struct's protocol
+ # implementations, so inspecting or enumerating the params runs code chosen
+ # by the client.
+ defp struct?(map) when is_map(map) do
+ Map.has_key?(map, :__struct__) or
+ Enum.any?(map, fn {key, value} -> struct?(key) or struct?(value) end)
+ end
+
+ defp struct?([head | tail]), do: struct?(head) or struct?(tail)
+ defp struct?(tuple) when is_tuple(tuple), do: struct?(Tuple.to_list(tuple))
+ defp struct?(_other), do: false
The check sits in the one decoder used for this content type, so it covers every route that accepts it. The recursive clauses inspect map keys and values, list heads and tails, and tuple elements, which closes the nested variants of the same trick. The request fails with a 400 before the value becomes request parameters.
The patch closes the entry point in hexpm. It does not change Plug.Crypto, Plug, Ecto or DBConnection. Hex.pm lists separate hardening work for those libraries:
- A decoder option that rejects structs.
- Refusing struct body parameters in Plug.
- Checking that the binding is a list in Ecto.
- Not applying
:logcallbacks taken from stream structs in DBConnection.
How do I check if I was compromised?
No request indicators are published, so a self-hosted registry has to rely on its own access and application logs from the incident window.
Look for requests that carry the Erlang term content type. This command adapts the path to a common reverse-proxy log:
grep -Ei 'application/vnd\.hex\+erlang' /var/log/nginx/access.log
A hit is a lead, not proof, because legitimate Hex clients use the same content type. Correlate hits with error responses and with the application log. The exploit raises an UndefinedFunctionError from the struct lookup, and the error reporter then inspects Ecto.Query.DynamicExpr and DBConnection.Stream.
List files created by the registry user during the exploitation window:
find /srv/hexpm -newermt '2026-11-23 18:00:00' ! -newermt '2026-11-23 19:00:00' -type f
On hex.pm, files created by the exploit appeared on six servers, in one case three milliseconds after a request. A self-hosted operator should treat any unexpected file in that window as a lead and compare it with the release and asset records.
For hex.pm account holders, the server-side logs are not available. The vendor's account steps are the response: change the password, reset two-factor authentication, sign the clients in again and watch for phishing that uses the exposed email addresses.
Timeline
- 2016-02-23: commit
ab1bbceremoves the struct check from the Erlang term decoder. - 2026-11-23 18:16 UTC: the first exploit request reaches a hex.pm server.
- 2026-11-23 18:31 UTC: every hex.pm server runs the patched build.
- 2026-11-24: the CVE record and the incident report are published.
FAQ
Is the Hex client affected?
No. The flaw is in the hexpm server application, not in the mix hex client, rebar3 or Gleam. An organisation that runs its own copy of the registry is affected until it deploys the fix.
Were packages modified?
Hex.pm found no evidence of package modifications. It compared every database table with a copy taken two minutes before the first exploit request, and all 23 releases published during the attack match the audit log. No older release was changed.
Do I need to rotate my Hex API keys?
No. Hex.pm says API keys are random 128-bit values stored only as HMAC-SHA256 hashes, which it says cannot realistically be brute-forced. Passwords, two-factor secrets and sessions are different, and the vendor asks users to change the password and reset two-factor authentication.
Was account data stolen?
Hex.pm cannot rule it out. Database reads are not logged, and the database holds email addresses, password hashes, API key hashes, two-factor secrets, sessions and audit logs. The vendor reported a personal data breach to the Swedish data protection authority and notified CISA and ENISA.
Can I keep using a third-party mirror?
No. Hex.pm asks users to fetch packages only from repo.hex.pm until the client release with the new registry signing system ships. The registry signing key had not been rotated when the incident report was published.
Is CVE-2026-129514 in CISA KEV?
No. The CVE is not in the CISA Known Exploited Vulnerabilities catalog as of 2026-11-25, even though the vendor reports exploitation against its own service.
References
- Hex.pm security incident report, published 2026-11-24 (checked November 25, 2026)
- CVE-2026-129514 record, Erlang Ecosystem Foundation, published 2026-11-24 (checked November 25, 2026)
- GitHub advisory GHSA-9pmm-hf4r-27pg (checked November 25, 2026)
- Fix commit 379b0a2, "Refuse structs in Erlang term request bodies" (checked November 25, 2026)
- Commit ab1bbce, "Fix for some bad requests", 2016-02-23 (checked November 25, 2026)
erlang_format.exbefore the fix (checked November 25, 2026)plug_parser.exbefore the fix (checked November 25, 2026)- Elixir Forum clarification by the Hex.pm maintainers, published 2026-11-24 (checked November 25, 2026)
- Hex.pm package statistics, 27,274 packages, 287,406 versions and 12,094,471 downloads on 2026-11-24 (checked November 25, 2026)
- CISA Known Exploited Vulnerabilities catalog, catalog version 2026.11.24 (checked November 25, 2026)
Keep reading
