SecuFocus
Under the hoodAnnouncements

Hex.pm: one unauthenticated request ran commands on six servers

On 23 November 2026 an unauthorised third party exploited a flaw in the Elixir package registry to run commands on its web servers. The Hex team has published the full chain, from an Erlang request body to a shell command.

Cracked dark-glass software package cube, glowing green command lines escaping toward six distant servers

Generated image · SecuFocus

At a glance

Key points

A single unauthenticated request in Erlang term format was enough: the decoder let fake structs through, and the Inspect, Ecto and DBConnection chain ended in command execution as the BEAM user. Hex blocked the traffic and shipped a fix within 20 minutes, replaced the exposed credentials, and still cannot rule out database reads.

What happened

On 23 November 2026 an unauthorised third party exploited a vulnerability in hex.pm that let them run commands on the service’s web servers. In a post published on 24 November, the Hex team says it blocked the traffic and deployed a fix “within 20 minutes”. At 19:07 UTC it received an email security report describing the same vulnerability.

Load balancer logs record 69 malicious requests between 18:16 and 18:29 UTC. The attacker’s first request of any kind arrived at 18:14:21, the first exploit request at 18:16:00, and the last one to reach a server at 18:29:33. Commands ran on six web servers: the first file created appeared 3 ms after a request at 18:16:46. The count reached six because a restart at 18:28 brought up three new servers that were still on the vulnerable build.

The day continued with notifications: at 22:58 UTC Hex reported a personal data breach to IMY, the Swedish data protection authority; at 23:05 it reported the incident to the US Cybersecurity and Infrastructure Security Agency (CISA), which confirmed receipt at 23:43; at 23:26 it submitted an early warning to ENISA.

From request body to shell command

The entry point was a custom parser in the endpoint, handling the application/vnd.hex+erlang content type through Plug.Crypto.non_executable_binary_to_term/2 with the [:safe] option. That decoder rejects functions and new atoms but never checks maps. Because it runs before routing and authentication, any unauthenticated POST with that content type reached it on every route. An Elixir struct is only a map with a __struct__ key, so the attacker could send a value the runtime treats as a real struct, with every field of their choosing.

The decoded value becomes the request body parameters. Plug.MethodOverride then reads body_params["_method"], which calls fetch/2 on the module named in the struct; that function does not exist, so the request raises an UndefinedFunctionError with the attacker’s struct in the stack trace. The JSON log formatter then calls inspect on the request data and the stack-frame arguments. Inspect is a protocol, so it runs the implementation of the module named in __struct__, which is how the attacker picked the code that ran next — here Ecto.Query.DynamicExpr.

Ecto.Query.DynamicExpr’s Inspect implementation enumerates the binding field without checking that it is a list, and enumeration is itself a protocol call, so a struct placed in that field is dispatched to another implementation. That struct was a DBConnection.Stream, whose Enumerable calls DBConnection.reduce/3 and then declare/4. Encoding the query failed before any connection was checked out, but the error path still ran the stream’s :log option: a {module, function, args} tuple taken from the request, which db_connection applied with the log entry prepended. A tuple supplied by the attacker reaches functions in loaded libraries and the standard library, which is how operating system commands ended up running as the BEAM’s user.

What the attacker could read

Hex found no evidence of unauthorised package modifications, no database changes, and no sign that the attacker kept access. It cannot rule out access to data stored in the database, however, because reads are not logged: email addresses, password hashes, API key hashes, 2FA secrets, sessions and audit logs are all in scope.

Every file written to package storage during the incident was checked against the database: the 62 package files written since 18:00 match their stored checksums, and the 186 registry files written since 18:00 match the database contents. Documentation archives have no stored checksum to compare against. Reads of private packages in that period came from Hex’s own servers and coincide with releases the same organisations published at the time; a read from a compromised server would look the same, so one cannot be fully ruled out, and reads of private documentation are not logged. Affected organisations will be contacted directly.

Every credential the attacker’s commands could read was replaced: storage, CDN, email and database credentials, plus the keys that sign sessions and access tokens, which logged everyone out of hex.pm and the Hex clients. Network traffic stayed within normal levels apart from one worker server that peaked at 0.47 MB/s against a usual maximum of 0.29 MB/s. The database password followed on 24 November; the registry signing key and a few low-impact secrets were the exception, and a new signing system with key rotation is in preparation.

The fix and the hardening to come

The fix, commit 379b0a2 in the hexpm repository, makes the decoder reject any term containing a map with a __struct__ key and return a 400. Because the check sits in the only decoder used for this format, it covers every route that accepts it: no fake struct can reach the request parameters any more. Every hex.pm server was running the patched build by 18:31 UTC. The EEF advisory CVE-2026-129514, published on 24 November, gives the affected range as the commits from ab1bbcef7cc8395d1056d3b1aa6a174353492d59 up to but excluding 379b0a29bcc95164249f38ad7d772a37a8ff9533, and scores the flaw 10.0 under CVSS 4.0 (CWE-502, deserialization of untrusted data).

Four upstream hardening changes are announced: plug_crypto should document that its decoder is only safe for authenticated payloads and add an option to reject structs; plug should refuse struct values as body parameters; ecto should check that binding is a list before enumerating it in Inspect; and db_connection should stop applying :log callbacks taken from stream structs, a point tracked as CVE-2026-133555.

The investigation also turned up the same class of flaw in Ash, whose keyset pagination accepted crafted structs in client-supplied cursors and could lead to command execution or SQL injection. It is tracked as CVE-2026-124283 and was fixed in ash 3.38.0 on 24 November. The git history of the request decoder also shows the safety check was removed on 23 February 2016, so the flaw had been present since 2016.

What users still need to do

Hex asks users to change their password on hex.pm, then reset 2FA at hex.pm/dashboard/security: under “Authenticator App”, choose “Setup New App” and verify a code from the new entry, which yields a new secret and new recovery codes to store. This also works when an organisation requires 2FA and refuses to let it be disabled.

The Hex client should be updated once the release carrying the new signing system ships in the coming days. Until then, Hex asks users to fetch packages only from repo.hex.pm and never from a third-party mirror: mix local.hex --force for the client, then update rebar3 or Gleam if they are in use. The new signing infrastructure will support key rotation.

API keys do not need to be rotated: they are 128-bit random values stored as HMAC-SHA256, and 128 bits of randomness is far beyond the reach of brute force. Passwords are hashed with bcrypt, which slows guessing but does not protect a weak password, so Hex asks users to change them. Because email addresses may have been exposed, check that links in any message claiming to come from Hex really lead to hex.pm, and forward suspicious messages to security@hex.pm.

Check and explore

Sources for this article

Numbers connect each reference to the passages that use it. Dates show when the documentation was consulted.

This article draws on the sources above. The exercises are for you to try on your devices; SecuFocus does not present them as tests carried out by its editorial team. Interfaces and features can change. Method and corrections.

Cite this article

Keep this reference with the article when you save or share it.