On 23 November 2026, someone sent 69 requests to hex.pm, the package registry for Elixir and Erlang, and ran operating system commands on six of its web servers. The hole had been open since 23 February 2016. The exploited line decoded untrusted input with Plug.Crypto.non_executable_binary_to_term(binary, [:safe]), which is the call Elixir’s own security tooling tells you to switch to. We read the 1,000 most downloaded Hex packages to see who follows that advice, and who already does better.
TL;DR
- Hex.pm was breached through CVE-2026-129514 (CVSS 4.0 score 10), an unauthenticated request body decoder that let attacker-built Elixir structs into request params.
- The code that actually ran the attacker’s command was the error reporting path. Sentry and the loggers called
inspecton the poisoned params, and the struct chose which code ran next. - Of the four Elixir security checkers in the top 1,000 Hex packages, three pass the exact line hex.pm ran. Two of them recommend it as the fix.
- 74 of the 1,000 packages decode Erlang terms in shipped code. Of the 10 we could trace to client or peer input, four verify a signature first, four check the shape of the result, and two do neither.
- The lesson travels beyond Elixir: a “safe” deserialiser flag limits which types you get back, not who is allowed to send them.
What happened in 13 minutes
The Hex team’s incident report is unusually precise, and worth reading in full. The short version, all times UTC:
- 18:16:00: first exploit request; Sentry records an error for every one.
- 18:27: firewall rule added. A restart at 18:28 brought up three fresh servers still on the vulnerable build, which is how three servers became six.
- 18:29:33: last exploit request to reach a server.
- 18:30 to 18:31: every web, worker and job server replaced with a patched build.
- 22:58: personal data breach reported to IMY, the Swedish data protection authority, 4 hours 42 minutes after the first request.
- 23:26: early warning submitted to ENISA.
The team found no modified packages or database writes. Reads are not logged and could not be ruled out, so every user was logged out and asked to reset their password and 2FA.
The chain: your error reporter runs the exploit
The interesting part is where the code execution happened.
hex.pm accepted request bodies in Erlang’s external term format. non_executable_binary_to_term with [:safe] refuses anonymous functions and new atoms, but not maps. In Elixir, a struct is just a map with a __struct__ key naming a module, so the attacker could send a map that the runtime treats as any struct they liked, with every field under their control.
A request handler tripped over the fake struct and raised an error with it in the stack trace. Error reporting then called inspect on it, which in Elixir is a protocol: the module named in __struct__ decides what happens. The attacker named Ecto.Query.DynamicExpr, whose inspect implementation enumerated a field holding a DBConnection.Stream, whose error path applied a {module, function, args} logging callback taken straight from the request. That is arbitrary function execution, and from there, a shell.
Every library in that chain was doing something reasonable on its own. The vulnerability existed only in the composition, and it was triggered by the code path most teams think of as passive observability.
The fix, committed about 11 minutes after the first exploit request, is about a dozen lines: walk the decoded term and return a 400 if any map in it has a __struct__ key.
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
What the security linters say
We pulled the top 1,000 packages by recent downloads from the Hex API on 24 November, fetched each release tarball from repo.hex.pm, and read the source. Four of those packages are security checkers that look at binary_to_term. We ran the hex.pm line past each rule as written.
| Checker | Version | Verdict on hex.pm’s line |
|---|---|---|
| Sobelow | 0.19.0 (12 Nov 2026) | Silent. Its docs say to “prefer” this exact call for untrusted input, and that the combination “is omitted by this check”. |
| jump_credo_checks | 0.7.1 | Silent. Its docs list this call as the “Good” example and name “a pagination cursor, a request param, a webhook body” as the inputs it protects. |
| Reach | 2.8.4 | Silent. It only inspects calls on the :erlang module, so the Plug.Crypto wrapper is never examined. |
| oeditus_credo | 0.12.0 | Flags it: every call to the function “requires strict trust boundary validation”. |
To be fair to Sobelow, its documentation also says to “validate the resulting types and structure”. But a linter’s output is its verdict, and here the verdict is silence. Jump is right about what [:safe] covers: atom table exhaustion, a denial of service. The trouble is that the flag is widely read as covering code execution too, and on the BEAM a struct is code selection.
Only oeditus_credo draws the line at the trust boundary rather than the option list.
What the other 74 packages do
74 of the 1,000 packages call binary_to_term in shipped code, not counting the security tools. Most read data the package wrote itself, such as locale tables, build manifests and caches. That is the format’s intended use.
We hand-traced the calls whose input plainly arrives from a client or a network peer. There were 10, and they fall into three groups.
- Authenticate first (4). Plug’s cookie session store, Ash’s keyset pagination since 3.38.0, Anubis MCP’s echoed request state and Jido AI’s ReAct tokens all verify a signature or MAC before a single byte is decoded. An attacker cannot reach the decoder at all.
- Check the shape (4). Flop’s pagination cursor walks the decoded term and raises if any map has a
__struct__key, which is precisely the hex.pm fix, already in place. Ash Admin checks the decoded primary key against the resource’s real fields, ChromicPDF accepts only a{:v1, signed}envelope and then verifies the signed part, and Swoosh’s test sandbox accepts nothing but a process identifier. - Neither (2). Two decode client or peer supplied terms with no signature and no struct check. We have not built exploits and are not naming them here; that conversation belongs with the maintainers, not on a blog.
The Ash entry matters. While investigating, the Hex team found the same class of bug in Ash’s keyset pagination (CVE-2026-124283), and the fix that shipped in 3.38.0 on 24 November does both: it signs the cursor, then rejects any decoded value that contains an Ash expression. That is the pattern to copy.
This is not an Elixir problem
Every mainstream stack has an over-trusted “safe” deserialiser switch. PHP’s unserialize with allowed_classes, Python’s restricted unpicklers, Java’s deserialisation filters and YAML’s safe loaders all narrow the set of types you get back. None of them answer the question that matters, which is whether this input should be deserialised into native objects at all. We made the same argument about React’s Flight protocol in July.
The second lesson is about error handling. Logging and error reporting touch attacker-controlled data by design, on exactly the requests your happy path rejected. If your runtime lets data choose its own formatting code, through protocols, __repr__, toString or __toString, your observability pipeline is part of your attack surface.
A checklist for your own codebase
- Find every native deserialiser that touches a request. Grep for
binary_to_term,unserialize,pickle.loads,ObjectInputStreamandyaml.load, then trace each input. - Prefer JSON at the boundary. Client input should decode into plain data, not types your runtime dispatches on.
- If you must decode native terms, sign them. A token you issued and can verify is not untrusted input. Four of our ten client-facing packages had already reached this conclusion.
- Otherwise, validate the shape before anything else touches it, including your error handler. Reject structs, objects and anything that is not the plain value you expect.
- Treat linter silence as the absence of one known pattern, not as approval. Three of four checkers would have waved hex.pm’s line through.
- Rehearse the paperwork. Hex reached its regulator in under five hours; GDPR allows 72, and NIS2 expects an early warning within 24. Most small teams have never timed either. Our piece on NIS2 reaching you through contracts covers why that may apply sooner than you think.
The takeaway
Hex.pm’s response was close to a model: patched fleet in 15 minutes, regulators informed the same evening, and a write-up that says plainly what it cannot rule out. The bug survived ten years because the code followed the advice, and the advice was about the wrong threat. A [:safe] flag is a type filter. Only authentication and validation tell you whether to trust what comes out.
REPTILEHAUS reviews web applications, APIs and DevOps pipelines for exactly this kind of composed risk, which no single linter rule catches. If you would like a second pair of eyes on where your untrusted input ends up, get in touch.
📷 Photo by Bradyn Trollip on Unsplash
