Elixir and the BEAM for AI systems

Hex.pm RCE: What to Check in Your Elixir App

An attacker ran commands on six hex.pm servers on Nov 23. Reset your password and 2FA, use only repo.hex.pm, bump db_connection and ash. How the chain worked.

In this post
  1. What to do
  2. How the chain worked
  3. What I checked on my own apps
  4. Find your own binary_to_term calls
  5. Related

On November 23, 2026, an attacker ran commands on six hex.pm web servers by sending unauthenticated requests. Hex blocked the traffic and deployed a fix within 20 minutes and found no evidence that any package was modified. They can’t rule out database reads, though, so email addresses, password hashes, API key hashes and 2FA secrets may have been exposed. If you have a hex.pm account, do three things today: change your password, set up 2FA again, and fetch packages only from repo.hex.pm until the next Hex client ships.

I have a hex.pm account, so I did the first two. The rest of this post is the full checklist, how the attack worked, and what I looked for in my own Phoenix apps.

What to do

  1. Change your password at hex.pm. Hex says passwords are hashed with bcrypt, which “slows guessing but doesn’t prevent it for a weak password.”

  2. Reset your 2FA. Go to hex.pm/dashboard/security, and under “Authenticator App” choose “Setup New App” and verify a code from the new entry. That gives you a new secret and new recovery codes, so save the codes again. Hex says this works even when an organization requires 2FA, where just disabling it is refused.

  3. Use only repo.hex.pm, with no third-party mirrors. Hex rotated every credential the attacker could have read except the registry signing key and a few low-impact secrets, and is building a new registry signing system that supports key rotation. Their words: “Until then, don’t trust third-party mirrors and fetch packages only from repo.hex.pm.” When the new Hex client is out, run mix local.hex --force, and update rebar3 or Gleam if you use them. As of November 26 the latest Hex release is still v2.7.0 from November 6, which predates the incident, so there is nothing to update to yet.

  4. Bump db_connection to 2.10.3 or later, and ash to 3.38.0 or later, if you use them. Both shipped fixes on November 24. The advisories are CVE-2026-133555 for db_connection and CVE-2026-124283 for ash. The Ash one is a separate hole of the same type that Hex found while investigating: its keyset pagination accepted crafted structs in client-supplied cursors, which could lead to command execution or SQL injection. If you run an Ash API with pagination exposed to clients, do that one first.

  5. Be careful with email that claims to come from Hex. Check that links lead to hex.pm, and forward anything suspicious to security@hex.pm. Your address may be in someone else’s hands now.

The rotation covered the keys that sign sessions and access tokens, which logged everyone out of hex.pm and the Hex clients. Hex says API keys don’t need rotating, because they are 128-bit random values stored as HMAC-SHA256 hashes.

The advisory for hex.pm itself is CVE-2026-129514.

How the chain worked

Hex’s post walks through the attack in seven steps. This is my summary. Most of the pieces are things a normal Phoenix app has.

  1. An Erlang-term parser sat in front of everything. hex.pm’s endpoint had a custom parser for the application/vnd.hex+erlang content type. It decoded request bodies with Plug.Crypto.non_executable_binary_to_term/2 and [:safe]. Endpoint parsers run before the router and before any auth plug, so a POST to any route got decoded, logged in or not.

  2. The decoder let structs in. It blocked functions and atoms that didn’t already exist, and it didn’t look at maps. In Hex’s words, “An Elixir struct is just a map with a struct key naming a module.” The attacker could name any module and fill in its fields.

  3. The struct caused a crash. The body params were now a struct where Plug expects a plain map. When Plug.MethodOverride looked up "_method" in it, Elixir tried to call fetch/2 on the named module. There is no such function, so the request raised UndefinedFunctionError and the struct went into the stack trace.

  4. Logging the crash ran inspect on it. Hex names three callers: Sentry, Bandit’s error logging and the JSON log formatter. inspect on a struct dispatches to the Inspect implementation of the module in __struct__, so the attacker got to choose the code. They named Ecto.Query.DynamicExpr.

  5. Ecto enumerated a field. That Inspect implementation loops over the struct’s binding field and assumed it was a list. Enumerating is a protocol dispatch too, so a second fake struct in binding chose the next piece of code.

  6. db_connection ran a callback. The second struct was a DBConnection.Stream. Enumerating one calls DBConnection.reduce/3 and then declare/4. The query failed to encode, so no connection was ever checked out, but the failure path still invoked the stream’s :log option. The attacker had set :log to a {module, function, args} tuple, and db_connection applied it.

  7. That was command execution. Applying any {module, function, args} means calling any function in the standard library or a loaded dependency, and from there OS commands as the BEAM’s user.

None of those steps is unusual on its own. The bug was also old: Hex’s git history shows the safety check on that decoder “was removed on February 23, 2016,” so the hole was open for more than ten years. Hex’s review of the attacker’s addresses since November 19 found repeated downloads of hex.pm’s own dependencies, which they read as the attacker building a local copy to test against.

The fix, and what is coming

Hex’s fix is commit 379b0a2. The decoder now returns a 400 for any term that has a map with a __struct__ key anywhere in it. Every hex.pm server was on the patched build by 18:31 UTC on November 23. Hex also lists hardening for libraries you probably depend on. One has shipped and three are planned:

  • plug_crypto: the docs will say the decoder is safe only on authenticated input, and a new option will reject structs.
  • plug: body params that are structs get refused.
  • ecto: the Inspect code checks that binding is a list first.
  • db_connection: :log callbacks from a stream struct are no longer applied. This one has shipped, as 2.10.3.

The plug_crypto repo already has a November 24 commit titled “More disclaimers on non_executable_binary_to_term.”

What I checked on my own apps

This site runs Phoenix, so I checked its code and mix.lock against each link in the chain.

  • Parsers. The endpoint’s Plug.Parsers accepts :urlencoded, :multipart and :json only. There is no Erlang-term parser, so no request body goes through binary_to_term.
  • MethodOverride. Plug.MethodOverride is in the endpoint, the same as it was on hex.pm. But JSON and urlencoded bodies decode to plain maps with string keys, so they can’t produce a struct.
  • Other binary_to_term calls. None in lib/. In deps, every real call site is on trusted input. Plug’s cookie session store calls Plug.Crypto.non_executable_binary_to_term, but only after verifying the signature, which is the authenticated case. plug_crypto’s own token code decodes only after verifying or decrypting. Req’s load_cache reads its own local cache file. The swoosh hit is example code in the sandbox adapter’s docs, not code that runs.
  • The later hops. No Sentry, no Ecto or db_connection, and no Ash in mix.lock. Bandit is there, and its error logging is one of the inspect callers Hex names, so the inspect step exists here too. What’s missing is a way for a request to put a struct in front of it.

The EnergyConnect marketing site also runs Phoenix, so I checked that one myself too. The main EnergyConnect app is TypeScript on Express, so this chain doesn’t apply to it.

If you want to check your own app, the questions in order are these. What content types do your endpoint parsers accept? Is there a custom parser anywhere? Which libraries in your error and log path call inspect on request data? Do you have Sentry, Ecto or Ash in the lock file? The chain needs a decoder that accepts structs from the outside and something downstream that turns a struct into code, so removing either one stops it.

Find your own binary_to_term calls

Decoding Erlang terms from someone you haven’t authenticated is the risk. binary_to_term can build any term the VM can represent, and hex.pm’s decoder only rejected functions and new atoms, which let a map with a __struct__ key through.

The new plug_crypto disclaimer, on GitHub main and not yet in a Hex release as of November 26, strongly advises signing or encrypting the payload and verifying it on receipt, because {module, function, args} tuples can still be injected inside the decoded data, including inside structs.

Run this at the root of each Elixir project:

grep -rn "binary_to_term" lib/

A hit means you are decoding Erlang terms somewhere, and you need to know where the bytes come from. If they come from a signed cookie, a file you wrote or a message between your own nodes, that is input you control. If they come from a request body, a webhook, an upload or a queue anyone can write to, replace it with JSON or another format that only produces plain data. Then run grep -rn "binary_to_term" deps/ and read the callers of any hit that sits on a request path.

This is the second time in about five weeks that Elixir teams have had to stop and check their dependencies. In October I wrote about what the eMudhra CA distrust did to Elixir apps, where bumping castore usually does nothing for an app on Req.

I do fractional CTO and vCISO work for pre-Series-A AI startups, and checking whether an advisory like this reaches your stack is part of it. The details are on my consulting page.