Am I affected?

type your hexpm/hexpm version to check

Description

Deserialization of Untrusted Data vulnerability in the application/vnd.hex+erlang request body parser in hexpm hexpm allows an unauthenticated remote attacker to execute operating system commands via a crafted Erlang external term format request body. This vulnerability was actively exploited against the hex.pm service on 2026-11-23.

HexpmWeb.ErlangFormat.decode/1 in lib/hexpm_web/erlang_format.ex decodes the body with Plug.Crypto.non_executable_binary_to_term/2, which accepts maps that have a __struct__ key. HexpmWeb.PlugParser.parse/5 returns the decoded term as the request params. The parser runs in the endpoint before routing and authentication, so a POST to any route reaches it. Elixir dispatches protocols on the __struct__ key, so the client selects which Inspect and Enumerable implementations run when error reporting inspects the params. A chain through Ecto.Query.DynamicExpr and DBConnection.Stream reaches an apply/3 call on a {module, function, args} tuple taken from the request body.

This issue affects hex.pm: from 2016-02-23 before 2026-11-23; hexpm/hexpm: from ab1bbcef7cc8395d1056d3b1aa6a174353492d59 before 379b0a29bcc95164249f38ad7d772a37a8ff9533.

Technical analysis

1. Decoding. HexpmWeb.Endpoint runs Plug.Parsers with HexpmWeb.PlugParser ahead of the router, so the parser handles every route before any authentication plug. For the content type application/vnd.hex+erlang, HexpmWeb.PlugParser.parse/5 passes the body to HexpmWeb.ErlangFormat.decode/1, which calls Plug.Crypto.non_executable_binary_to_term/2 with [:safe]. That function refuses functions and new atoms. It places no restriction on maps, so a map with a __struct__ key passes. In a release every module and function name is an existing atom. When the decoded term is a map, the parser returns it as the body params, and Plug.Parsers merges it into conn.params.

2. The error. An Elixir struct is a map whose __struct__ key names a module, and protocol dispatch tests only that key. Plug.MethodOverride evaluates body_params["_method"] on every POST. For a struct, Access.get/3 calls fetch/2 on the named module. Ecto.Query.DynamicExpr does not define fetch/2, so the call raises UndefinedFunctionError, and the top stack frame holds the decoded struct as an argument.

3. Inspect dispatch. Error reporting calls inspect/1 on the request data and on the stack frame arguments (Sentry, the Bandit error log through Exception.format/3, and the JSON log formatter). inspect/1 selects Inspect.Ecto.Query.DynamicExpr, which calls Enum.map/2 on the binding field without a check that the field is a list.

4. Enumerable dispatch. The binding field holds a DBConnection.Stream struct. Its Enumerable implementation calls DBConnection.reduce/3, which takes conn, query, params and opts from the struct and calls declare/4.

5. Function call. declare/4 reads the :log option from opts. Query encoding fails before a connection is checked out, and the error path still calls the log hook. For a {module, function, args} tuple the hook is apply(mod, fun, [entry | args]). All three values come from the request body. The log entry takes the first argument position, so the request names an OTP standard library function that applies a trailing module, function and argument list. The inner call runs an operating system command as the user of the BEAM process.

The Inspect implementation of a struct runs inside a rescue in Inspect.Algebra, so the request ends with the ordinary 500 response for the Plug.MethodOverride error.

The fix makes HexpmWeb.ErlangFormat.decode/1 return an error when any map in the decoded term has a __struct__ key. The parser turns that error into a 400 response.

Weaknesses & attack patterns

Weakness

CWE-502 · Deserialization of Untrusted Data in catalog → MITRE ↗

Attack patterns

CAPEC-586 · Object Injection MITRE ↗

An unauthenticated attacker can run operating system commands as the user of the BEAM process. That user can read the environment of the application, which holds the database URL, the storage credentials and the registry signing key.

Affected — hexpm / hexpm

≥ 2016-02-23 < 2026-11-23 affected
every other version: unaffected
cpe cpe:2.3:a:hexpm:hexpm:*:*:*:*:*:*:*:*
version type date
modules · source files · routines
modules 'Elixir.HexpmWeb.ErlangFormat' · 'Elixir.HexpmWeb.PlugParser'
source files lib/hexpm_web/erlang_format.ex · lib/hexpm_web/plug_parser.ex
routines 'Elixir.HexpmWeb.ErlangFormat':decode/1 · 'Elixir.HexpmWeb.PlugParser':parse/5

Affected — GitHub / hexpm/hexpm Repository ↗

≥ ab1bbce < 379b0a2 affected
every other version: unaffected
cpe cpe:2.3:a:hexpm:hexpm:*:*:*:*:*:*:*:*
version type git
modules · source files · routines
modules 'Elixir.HexpmWeb.ErlangFormat' · 'Elixir.HexpmWeb.PlugParser'
source files lib/hexpm_web/erlang_format.ex · lib/hexpm_web/plug_parser.ex
routines 'Elixir.HexpmWeb.ErlangFormat':decode/1 · 'Elixir.HexpmWeb.PlugParser':parse/5

References

Credits

Eric Meadows-Jönsson Analyst Remediation developer
Jonatan Männchen / EEF Analyst Coordinator
Peter Ullrich Analyst
Wojtek Mach Analyst

CVSS breakdown

CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H/E:A

Exploitability

Attack Vector
Network
Attack Complexity
Low
Attack Requirements
None
Privileges Required
None
User Interaction
None

Vulnerable System

Confidentiality
High
Integrity
High
Availability
High

Subsequent Systems

Confidentiality
High
Integrity
High
Availability
High
« All CVEs