Security incident on Hex.pm
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Security incident on Hex.pm
On November 23, 2026, an unauthorized third party exploited a vulnerability in hex.pm that let them run commands on our web servers. We blocked the traffic and deployed a fix within 20 minutes. Shortly afterwards we received a report of this exact vulnerability.
2026年11月23日,一名未经授权的第三方利用了 hex.pm 的一个漏洞,使其能够在我们的 Web 服务器上运行命令。我们在 20 分钟内拦截了流量并部署了修复程序。此后不久,我们收到了关于该漏洞的准确报告。
We found no evidence of unauthorized package modifications, or database changes, or that the attacker maintained access to our systems. However, because database reads are not logged, we cannot rule out that the attacker accessed data stored in the database, including email addresses, password hashes, API key hashes, 2FA secrets, sessions, and audit logs.
我们没有发现任何未经授权修改软件包、更改数据库或攻击者持续访问我们系统的证据。然而,由于数据库读取操作未被记录,我们无法排除攻击者访问了存储在数据库中的数据,包括电子邮件地址、密码哈希、API 密钥哈希、双重身份验证(2FA)密钥、会话和审计日志。
Because email addresses may have been exposed, be careful with emails that claim to come from Hex. Please double-check that the links they contain lead to hex.pm. Please forward suspicious emails to security@hex.pm.
由于电子邮件地址可能已泄露,请对声称来自 Hex 的邮件保持警惕。请仔细检查邮件中的链接是否指向 hex.pm。请将可疑邮件转发至 security@hex.pm。
We checked every file written to package storage during the incident against our database and found nothing unexpected. Reads of private packages in that period came from our own servers and coincide with releases the same organizations published at the time. A read made from a compromised server would look like one of ours, so we can’t fully rule one out, and reads of private documentation aren’t logged. We will contact affected organizations directly.
我们核对了事件期间写入软件包存储的所有文件,未发现异常。在此期间对私有软件包的读取操作均来自我们自己的服务器,且与相关组织当时发布的版本相吻合。由于来自受损服务器的读取请求看起来与我们的请求无异,我们无法完全排除这种可能性,且私有文档的读取操作未被记录。我们将直接联系受影响的组织。
The attacker’s commands could read the credentials our servers use, so we replaced them: the storage, CDN, email and database credentials, and the keys that sign sessions and access tokens. This logged everyone out of hex.pm and Hex clients.
攻击者的命令可以读取我们服务器使用的凭据,因此我们更换了这些凭据:包括存储、CDN、电子邮件和数据库凭据,以及用于签署会话和访问令牌的密钥。这导致所有用户从 hex.pm 和 Hex 客户端中登出。
We’re building a new registry signing system that supports key rotation, with new Hex client releases in the coming days. Until then, don’t trust third-party mirrors and fetch packages only from repo.hex.pm. We already deployed fixes for the vulnerability and are working on further hardening fixes.
我们正在构建一个新的支持密钥轮换的注册表签名系统,并将在未来几天发布新的 Hex 客户端。在此之前,请勿信任第三方镜像,仅从 repo.hex.pm 获取软件包。我们已经部署了针对该漏洞的修复程序,并正在进行进一步的加固工作。
What you should do
您应该采取的措施
Change your password at hex.pm. Reset your 2FA at hex.pm/dashboard/security: under “Authenticator App”, choose “Setup New App” and verify a code from the new entry. You get a new secret and new recovery codes, so store the new codes. This works when an organization requires 2FA, where disabling it is refused.
在 hex.pm 修改您的密码。在 hex.pm/dashboard/security 重置您的 2FA:在“Authenticator App”下,选择“Setup New App”并验证来自新条目的代码。您将获得新的密钥和新的恢复代码,请妥善保存这些新代码。当组织强制要求使用 2FA 且不允许禁用时,此操作同样适用。
Update your Hex client when the release with the new signing system is out in the coming days. Until then, use only repo.hex.pm, not mirrors. To update, run mix local.hex —force, and update rebar3 or Gleam if you use them.
在未来几天发布包含新签名系统的版本后,请更新您的 Hex 客户端。在此之前,仅使用 repo.hex.pm,不要使用镜像。如需更新,请运行 mix local.hex --force,如果您使用 rebar3 或 Gleam,也请一并更新。
Timeline
时间线
All times are in UTC. November 23, 2026 18:16 - 18:29: The attacker sent 69 malicious requests to hex.pm, six of our web servers were affected. Our error tracker Sentry recorded its first error at 18:16:00 and recorded an error for each request.
所有时间均为 UTC 时间。2026 年 11 月 23 日 18:16 - 18:29:攻击者向 hex.pm 发送了 69 个恶意请求,我们的 6 台 Web 服务器受到影响。我们的错误跟踪器 Sentry 在 18:16:00 记录了第一个错误,并为每个请求记录了一个错误。
18:27: We added a firewall rule to block the attacker’s traffic, which took full effect between 18:30 and 18:33. 18:30 - 18:31: All hex.pm servers were replaced with a patched build that rejects these payloads. 18:33 - 18:38: All further requests from the attacking address were denied.
18:27:我们添加了一条防火墙规则以拦截攻击者的流量,该规则在 18:30 至 18:33 之间完全生效。18:30 - 18:31:所有 hex.pm 服务器均被替换为拒绝此类负载的修补版本。18:33 - 18:38:来自攻击地址的所有后续请求均被拒绝。
18:35: We began investigating production logs and the database. 18:49: We deactivated the AWS access key the affected servers used, after creating a replacement at 18:47. 19:07: We received an email with a security report that described the same vulnerability.
18:35:我们开始调查生产日志和数据库。18:49:在 18:47 创建替换密钥后,我们停用了受影响服务器使用的 AWS 访问密钥。19:07:我们收到了一封包含描述相同漏洞的安全报告的电子邮件。
20:21: Most infrastructure credentials were rotated. The database password followed on November 24. 22:58: We reported a personal data breach to IMY, the Swedish data protection authority. 23:05: We reported the incident to CISA, the US Cybersecurity and Infrastructure Security Agency, which confirmed receipt at 23:43. 23:26: We submitted an early warning to ENISA, the EU Agency for Cybersecurity.
20:21:大部分基础设施凭据已轮换。数据库密码于 11 月 24 日完成轮换。22:58:我们向瑞典数据保护局 (IMY) 报告了个人数据泄露事件。23:05:我们向美国网络安全与基础设施安全局 (CISA) 报告了该事件,该机构于 23:43 确认收到。23:26:我们向欧盟网络安全局 (ENISA) 提交了预警。
November 24, 2026 By 10:42: We had rotated every credential the attacker could have read, including the database password, except the registry signing key and a few low-impact secrets. 13:48: We published CVE-2026-129514.
2026 年 11 月 24 日 10:42 前:我们已轮换了攻击者可能读取的所有凭据(包括数据库密码),仅剩注册表签名密钥和少数低影响的密钥。13:48:我们发布了 CVE-2026-129514。
The vulnerability
漏洞详情
The vulnerability in Hex.pm is tracked as CVE-2026-129514. hex.pm decoded unauthenticated request bodies in Erlang term format with Plug.Crypto.non_executable_binary_to_term/2 which blocks most potentially harmful terms, but allows struct values through. These decoded struct values, when chained together correctly, turned into a remote command execution (RCE).
Hex.pm 中的该漏洞被追踪为 CVE-2026-129514。hex.pm 使用 Plug.Crypto.non_executable_binary_to_term/2 以 Erlang 术语格式解码未经身份验证的请求体,该函数虽然阻止了大多数潜在有害的术语,但允许结构体(struct)值通过。这些解码后的结构体值在正确链接时,可导致远程代码执行(RCE)。
This is the detailed playbook of the attack: The entry point. A custom parser in the endpoint handled the application/vnd.hex+erlang content type using Plug.Crypto.non_executable_binary_to_term/2 with [:safe]. Because the endpoint runs this parser before routing and authentication, any unauthenticated POST with that content type reached it on every route.
以下是攻击的详细过程:入口点。端点中的自定义解析器使用带有 [:safe] 参数的 Plug.Crypto.non_executable_binary_to_term/2 处理 application/vnd.hex+erlang 内容类型。由于端点在路由和身份验证之前运行此解析器,因此任何带有该内容类型的未经身份验证的 POST 请求都会在每个路由上触发它。
Fake structs got through. The decoder rejected functions and new atoms, but it never checked maps. An Elixir struct is just a map with a struct key naming a module. That meant the attacker could send a value the runtime treats as a real struct, with every field set to whatever they chose.
伪造的结构体得以通过。解码器拒绝了函数和新原子,但从未检查映射(map)。Elixir 结构体本质上只是一个带有 __struct__ 键(指向模块名)的映射。这意味着攻击者可以发送一个运行时视为真实结构体的值,并将每个字段设置为他们选择的任何内容。
Converting the structs into an error. The decoded struct became the request’s body parameters. Plug.MethodOverride then read body_params[“_method”], which on a struct calls fetch/2 on the struct’s module. That function didn’t exist, so the request raised an UndefinedFunctionError with the attacker’s struct in the stack trace.
将结构体转换为错误。解码后的结构体成为了请求的体参数。随后 Plug.MethodOverride 读取 body_params["_method"],这会在结构体上调用其模块的 fetch/2 函数。由于该函数不存在,请求引发了 UndefinedFunctionError,且堆栈跟踪中包含了攻击者的结构体。
Error reporting runs inspect. Sentry, Bandit’s error logging, and the JSON log formatter call inspect on request data and stack-frame arguments. Inspect is a protocol, so for a struct it runs the implementation of the module named in struct, which let the attacker choose which code ran next. They chose Ecto.Query.DynamicExpr.
错误报告运行 inspect。Sentry、Bandit 的错误日志记录以及 JSON 日志格式化程序都会对请求数据和堆栈帧参数调用 inspect。inspect 是一个协议,因此对于结构体,它会运行 __struct__ 中命名的模块的实现,这让攻击者可以选择接下来运行的代码。他们选择了 Ecto.Query.DynamicExpr。
The Ecto hop. The Inspect implementation for Ecto.Query.DynamicExpr enumerated the binding field without checking that it was a list. Enumeration is itself a protocol call, so a struct placed in that field is dispatched to another implementation. The DBConnection hop. The struct placed in binding was a DBConnection.Stream. Its Enumerable implementation calls DBConnection.reduce/3, which then calls declare/4. Encoding the query failed before any connection was checked out, but the error
Ecto 跳转。Ecto.Query.DynamicExpr 的 Inspect 实现枚举了 binding 字段,而未检查其是否为列表。枚举本身是一个协议调用,因此放置在该字段中的结构体会分派到另一个实现。DBConnection 跳转。放置在 binding 中的结构体是 DBConnection.Stream。其 Enumerable 实现调用 DBConnection.reduce/3,进而调用 declare/4。查询编码在任何连接被检出之前就失败了,但错误……