CVE-2026-129514 HIGH 8.8 난이도Difficulty 고급Advanced
Erlang term 요청 본문의 Struct 맵이 연쇄되어 Hex.pm 서버에서 원격 코드 실행으로 이어짐Struct Maps in Erlang Term Request Bodies Chain to Remote Code Execution in the Hex.pm Server
CVE-2026-129514는 hexpm (the hex.pm server)의 Deserialization of Untrusted Data(CWE-502) 취약점으로, CVSS 8.8(HIGH)입니다. 영향 버전: hexpm < commit 379b0a2. 수정 버전: commit 379b0a2.CVE-2026-129514 is a Deserialization of Untrusted Data (CWE-502) vulnerability in hexpm (the hex.pm server), rated CVSS 8.8 (HIGH). Affected: hexpm < commit 379b0a2. Fixed in: commit 379b0a2.
| 제품Product | hexpm (the hex.pm server) |
|---|---|
| 영향 버전Affected | hexpm < commit 379b0a2 |
| 수정 버전Fixed in | commit 379b0a2 |
| 심각도Severity | CVSS 8.8 HIGH |
| 취약점 유형Weakness | CWE-502 Deserialization of Untrusted Data |
| 공격 조건Attack conditions | 원격 (네트워크) · 인증 불필요 · 사용자 상호작용 필요Remote (network) · No authentication · User interaction required |
1. TL;DR
hexpm 서버 애플리케이션(hex.pm의 기반 소프트웨어)은 콘텐츠 타입이 application/vnd.hex+erlang인 요청 본문을 받아 Plug.Crypto.non_executable_binary_to_term/2로 디코딩했다. 이 함수는 함수와 새 atom은 막지만 Elixir struct 값은 허용한다. struct는 모듈을 가리키는 __struct__ 키를 가진 맵이다. 이 파서는 라우팅과 인증보다 먼저 실행되므로, 인증 없이 어떤 경로에든 POST를 보내면 공격자가 고른 struct를 서버에 전달할 수 있었다(EEF CNA record).
공격자는 이 struct를 요청 params에 넣기만 하면 됐다. 나머지는 서버 자체의 오류 보고 기능이 처리했다. struct에 inspect를 호출하면 클라이언트가 고른 라이브러리 코드로 디스패치되었다. Ecto와 DBConnection 코드를 거치는 체인은 모듈, 함수, 인자를 모두 요청 본문에서 가져오는 apply/3 호출로 끝났다. 그 결과 BEAM 프로세스 사용자 권한으로 OS 명령이 실행되었다. Hex.pm은 이 취약점이 2026-11-23에 호스팅 서비스를 대상으로 악용되었다고 밝혔다(Hex.pm incident post).
수정은 __struct__ 키가 있는 맵을 포함한 디코딩 결과를 거부하고 HTTP 400을 반환하도록 한다.
2. Flaw 분류
| 항목 | 값 |
|---|---|
| 주요 CWE | CWE-502, 신뢰할 수 없는 데이터의 역직렬화(CNA는 CAPEC-586, Object Injection도 함께 기재) |
| 공격 벡터 | 네트워크. Erlang external term format 본문과 application/vnd.hex+erlang 콘텐츠 타입을 가진 비인증 HTTP POST |
| 영향 | BEAM 프로세스 사용자 권한의 OS 명령 실행. 이 사용자는 애플리케이션 환경을 읽을 수 있으며, CNA에 따르면 환경에는 데이터베이스 URL, 스토리지 자격 증명, 레지스트리 서명 키가 들어 있음 |
| 선행 조건 | 없음. 계정도 사용자 상호작용도 필요 없음. 요청이 취약한 엔드포인트에 도달해야 하며, 어떤 오류 보고 경로가 요청 데이터나 스택 프레임 인자에 inspect를 호출해야 함 |
| 심각도 | CVSS v3.1 8.8 High (AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H), CVSS v4.0 10.0 Critical (AV:N/AC:L/AT:N/PR:N/UI:N, E:A) — 둘 다 CNA 평가, NVD 분석 대기 중 |
| 영향 범위 | 2016-02-23부터 2026-11-23 이전까지의 hex.pm. hexpm/hexpm은 ab1bbce부터 379b0a2 미만까지 |
| 악용 여부 | CNA 기록과 Hex.pm 인시던트 게시물에 따르면 2026-11-23에 hex.pm을 대상으로 악용됨 |
3. 근본 원인
이 문제는 단일 버그가 아니다. 각각은 합리적인 여러 동작이 하나의 누락된 검사 때문에 결합되었다. 아래 각 항목은 CNA 기술 분석과 Hex.pm 인시던트 게시물을 따른다.
3.1 디코더가 “safe” 모드를 지나치게 신뢰함
HexpmWeb.ErlangFormat.decode/1은 [:safe]로 Plug.Crypto.non_executable_binary_to_term/2를 호출한다. 이 모드는 함수와 새 atom 생성을 거부한다. 맵에는 아무 제한도 두지 않는다. 릴리스에서는 모든 모듈과 함수 이름이 이미 atom으로 존재하므로, 본문은 새 atom을 만들지 않고도 로드된 어떤 모듈이든 가리킬 수 있다. Hex.pm의 이력을 보면 이 안전 검사는 2016-02-23에 제거되었다. 이는 영향 범위의 시작 시점과 일치한다.
3.2 디코딩된 값이 인증 전에 요청 params가 됨
HexpmWeb.PlugParser.parse/5는 디코딩된 term을 본문 params로 반환하고, Plug.Parsers가 이를 conn.params에 병합한다. 이 파서는 엔드포인트에서 라우터보다 앞에 있다. 아직 인증 plug가 실행되지 않았고, 어떤 경로인지도 상관없다.
3.3 struct는 그저 맵이며, 프로토콜은 하나의 키로 디스패치함
Elixir에서 struct는 __struct__ 키가 모듈을 가리키는 맵이다. 프로토콜 디스패치(Inspect, Enumerable 등)는 이 키만 확인한다. 값이 해당 모듈의 생성자로 만들어졌는지는 검사하지 않는다. 클라이언트가 __struct__ 값을 제어하면 어떤 프로토콜 구현이 실행될지, 그 구현이 어떤 데이터를 볼지도 제어한다. 이것이 이 역직렬화 취약점의 핵심이다. 클라이언트가 실행될 코드를 고르고, 실행되는 코드는 struct의 필드를 신뢰한다.
3.4 오류 보고가 공격자 데이터에 inspect를 호출함
Plug.MethodOverride는 모든 POST에서 body_params["_method"]를 읽는다. struct에 대해 Access.get/3은 지정된 모듈의 fetch/2를 호출한다. fetch/2를 정의하지 않은 모듈이면 UndefinedFunctionError가 발생하고, 스택 프레임에는 공격자의 struct가 인자로 들어 있다. 그러면 오류 보고기(CNA에 따르면 Sentry, Bandit 오류 로그, JSON 로그 포맷터)가 요청 데이터와 스택 프레임 인자에 inspect/1을 호출한다.
3.5 올바른 형식의 struct를 가정한 라이브러리 코드
CNA와 Hex.pm 게시물이 설명하는 두 가지 라이브러리 동작이 체인을 완성한다.
Ecto.Query.DynamicExpr의Inspect구현은binding필드가 리스트인지 확인하지 않고 열거한다. 열거는 또 다른 프로토콜 호출이므로, 그 필드에 넣은 struct는 다시 디스패치된다.DBConnection.Stream의Enumerable구현은 struct에서 연결, 쿼리, params, 옵션을 가져온다. 오류 경로에서도:log옵션을 실행한다. 이 옵션이{module, function, args}튜플이면 라이브러리는 로그 항목을 앞에 붙여 이를 apply한다. 세 값 모두 요청에서 온다.
4. 익스플로잇 흐름(개념)
각 단계는 전송되는 내용이 아니라 수행되는 동작을 기준으로 설명한다. 공격 입력은 의도적으로 제시하지 않는다.
- 진입점. 공격자가
application/vnd.hex+erlang콘텐츠 타입으로 아무 경로에 비인증 POST를 보낸다. 본문은 직렬화된 Erlang term이다. - struct 밀반입. 디코더가 term을 받아들인다. 함수와 새 atom은 막히지만, 이미 로드된 모듈을 가리키는
__struct__키를 가진 맵은 허용된다. 이 term이 요청 params가 된다. - 오류 유발.
Plug.MethodOverride가 params에서 키를 읽는다. 지정된 모듈에 맞는 접근 함수가 없어 실패한다. 예외는 스택 프레임에 struct를 담고 있다. - 오류 보고가 프로토콜을 디스패치함. 오류 보고기가 struct를 inspect한다. 클라이언트가 모듈을 골랐으므로, 실행되는
Inspect구현도 클라이언트가 고른 것이다. 그 구현은 공격자가 제어하는 필드를 열거하며, 이것이 두 번째 프로토콜 디스패치를 일으킨다. - 콜백 악용. 중첩된 struct가 DBConnection 스트리밍 코드에 도달한다. 그 오류 경로는 요청에서 가져온 모듈, 함수, 인자로 지정된 “log” 콜백을
apply/3으로 호출한다. - 영향. 공격자는 이 호출 기본 수단을 이용해 선택한 호출을 다시 실행하는 표준 라이브러리 함수에 도달한다. 이로써 BEAM 사용자 권한으로 OS 명령이 실행된다.
Inspect구현이 rescue 안에서 실행되므로 HTTP 클라이언트에는 평범한 500 응답만 보인다.
- 아무 경로로 POST — 비인증, vnd.hex+erlang 본문
- 디코더가 __struct__ 맵 허용 — conn.params로 유입
- MethodOverride에서 오류 발생
- 오류 보고기가 inspect 호출 — 클라이언트가 Inspect/Enumerable 구현을 선택
- log 훅 apply/3 — 본문의 MFA
- OS 명령 실행
5. 트리거 조건
- 서버 애플리케이션: hexpm 서버 코드. 호스팅된 hex.pm이거나 아직
379b0a2에 도달하지 않은 자체 호스팅hexpm/hexpm배포가 해당한다. Hex.pm 게시물은 Hex 클라이언트와 다른 도구는 취약한 구성 요소가 아니라고 밝히며, 이 취약점이 hex.pm 서버에 있다고 설명한다. - 입력 경로: 엔드포인트의
application/vnd.hex+erlang파서. 이 경로는 라우팅과 인증 이전에 모든 경로에서 접근할 수 있었다. - 가젯 존재 여부: 로드된 의존성에 체인을 제공하는 Ecto와 DBConnection 코드가 포함되어야 한다. CNA는 hexpm 자체의 의존성 집합에 대해 이 체인을 설명한다.
- 오류 보고: 오류 발생 후 어떤 구성 요소가 요청 데이터나 스택 프레임 인자에
inspect를 호출해야 한다. CNA는 Sentry, Bandit의 오류 로그, JSON 로그 포맷터를 언급한다. 이들 없이도 체인에 도달할 수 있는지는 공개 자료에서 확인되지 않았다. - 권한과 상호작용: 필요 없다.
- 우회 방법: GitHub 권고문에는 없다. 해결책은 패치다.
6. 패치 분석
수정은 “Refuse structs in Erlang term request bodies”라는 commit 379b0a2이다. 이 커밋은 lib/hexpm_web/erlang_format.ex를 변경하고 테스트를 추가한다. 변경의 핵심 부분은 다음과 같다.
def decode(binary) do
term = Plug.Crypto.non_executable_binary_to_term(binary, [:safe])
{:ok, term}
if struct?(term) do
{:error, "bad binary_to_term"}
else
{:ok, term}
end 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
defp struct?([head | tail]), do: struct?(head) or struct?(tail)
defp struct?(tuple) when is_tuple(tuple), do: struct?(Tuple.to_list(tuple))
defp struct?(_other), do: false이 변경이 흐름을 끊는 이유. 흐름의 2단계는 [:safe] 검사를 통과한 모든 term에 대해 디코더가 {:ok, term}을 반환하는 데 의존했다. 변경 후에는 term을 맵(키와 값), 리스트, 튜플을 따라 재귀적으로 순회한다. 어떤 맵이든 __struct__ 키가 있으면 디코딩은 오류를 반환하고, CNA에 따르면 파서는 이를 400으로 바꾼다. 이제 클라이언트는 struct를 params에 넣을 수 없으므로 이후의 프로토콜 디스패치 단계에는 도달하지 못한다. 중첩된 값까지 순회하는 점이 중요하다. 최상위 term만 검사하면 다른 구조 안에 숨은 struct를 놓친다.
이 검사는 해당 콘텐츠 타입에 쓰이는 단일 디코더에 있으므로, 이를 받아들이는 모든 경로를 포괄한다. Hex.pm 게시물은 이것이 진입점만 닫는다는 점을 강조한다. 체인이 더 아래에서도 끊기도록 다른 라이브러리에서 계획 중인 보강 작업을 다음과 같이 나열한다.
- plug_crypto: 디코더가 인증된 페이로드에만 안전하다는 점을 문서화하고, struct를 거부하는 옵션을 추가.
- plug: struct 값을 본문 params로 받지 않도록 거부.
- ecto:
Inspect에서 binding이 리스트인지 확인. - db_connection: 스트림 struct에서 가져온
:log콜백을 apply하지 않음(CVE-2026-133555로 추적).
게시물은 이들을 진행 중인 작업으로 설명한다. 릴리스 여부는 공개 자료에서 확인되지 않았다.
7. 탐지·완화
즉시 조치
- 호스팅 hex.pm 사용자: Hex.pm 게시물에 따라 비밀번호를 변경하고 2FA를 재설정한다. 새 서명 체계가 포함된 릴리스가 나오면 Hex 클라이언트를 업데이트하고, 그때까지는 미러가 아닌 repo.hex.pm만 사용한다.
- 자체 호스팅 hexpm 운영자:
379b0a2가 포함된 빌드를 배포하고 모든 노드를 재시작한다. 신뢰할 수 없는 트래픽에 노출된 수정 전 서버의 환경은 노출되었을 수 있다고 간주한다. CNA는 BEAM 사용자가 데이터베이스 URL, 스토리지 자격 증명, 레지스트리 서명 키를 읽을 수 있다고 밝힌다. 해당 자격 증명을 교체한다. 참고로 Hex.pm은 자체 인프라에서 공격자가 읽을 수 있었던 자격 증명을 교체했지만, 레지스트리 서명 키는 새 서명 체계를 만드는 중이라 아직 교체하지 않았다고 밝혔다(Hex.pm 보안 사고 공지). - 누락된 노드 확인: Hex.pm은 인시던트 중 서버 세 대가 이전 빌드로 다시 시작되었다고 밝혔다. 워커와 작업 서버를 포함해 이전 이미지를 실행 중인 노드가 없는지 확인한다.
- 일반 애플리케이션 개발자: 신뢰할 수 없는 입력을
binary_to_term이나 “safe” 변형에 넘긴 뒤 그 결과를 params로 쓰지 않는다. “safe” 옵션이 안전을 보장하지는 않는다. struct 맵을 거부하거나, 비인증 입력에는 이 형식을 쓰지 않는다.
탐지
- 오류 추적기와 로그: Hex.pm은 오류 추적기가 각 익스플로잇 요청에 대해 오류를 기록했고, 그렇게 공격을 탐지했다고 밝혔다. POST 요청에서
Plug.MethodOverride가 발생시킨 예외, 특히 예상치 못한 모듈 이름을 가진UndefinedFunctionError를 찾는다. CNA는 요청이 평범한 500 응답으로 끝난다고 설명한다. - 요청 패턴: 로드 밸런서나 접근 로그에서, 알려진 Hex 클라이언트가 아닌 출처가 평소에 이 콘텐츠 타입을 받지 않는 경로로 보낸
application/vnd.hex+erlangPOST를 찾는다. - 호스트 측: BEAM 사용자가 만든, 정상 동작과 맞지 않는 파일이나 프로세스를 찾는다. Hex.pm은 서버의 파일 생성 시각을 요청 시각과 대조했다. 데이터베이스 읽기, 환경 읽기, 셸 명령은 기본적으로 로깅되지 않으므로 증거가 없다는 사실의 의미는 약하다.
- 다른 BEAM 앱: 클라이언트가 제공한 Erlang term을 디코딩하는 코드를 검색한다. Hex.pm은 Ash keyset 페이지네이션 커서에서 같은 종류의 문제를 발견했다(Hex.pm 게시물에 따르면 CVE-2026-124283, ash 3.38.0에서 수정).
격리된 실습(로컬 Docker 랩)
인터넷과 격리된 로컬 Docker 랩에서만 재현한다. 외부로 나가는 접근이 없는 네트워크와 일회용 자격 증명을 사용한다. hex.pm이나 소유하지 않은 시스템을 대상으로 절대 테스트하지 않는다.
공격 입력 없이 제안하는 학습 목표는 다음과 같다.
- “safe” 모드로 Erlang term을 디코딩하는 커스텀 본문 파서를 가진 최소한의 Plug/Phoenix 앱을 만든다. 함수 값과 새 atom이 거부되는지 확인한 뒤, 이 검사가 다루지 않는 부분을 관찰한다.
iex에서inspect/1과Enum이 맵의__struct__값에서 구현을 선택하는 방식을 관찰한다. 직접 만든 무해한 struct로 실험한다.- 6절의 struct 거부 검사를 적용하고 파서가 이제 400을 반환하는지 확인한다.
- 자체 오류 보고기(Sentry, 로그 포맷터)가 요청 데이터를 어떻게 처리하는지, 그리고 이를 inspect할 때 어떤 코드에 도달할 수 있는지 검토한다.
8. References
1. TL;DR
The hexpm server application (the software behind hex.pm) accepted request bodies with the content type application/vnd.hex+erlang and decoded them with Plug.Crypto.non_executable_binary_to_term/2. That function blocks functions and new atoms but allows Elixir struct values. A struct is a map with a __struct__ key that names a module. Because the parser ran before routing and authentication, any unauthenticated POST to any route could hand the server an attacker-chosen struct (EEF CNA record).
The attacker only had to get this struct into the request params. The server’s own error reporting then did the rest. Calling inspect on the struct dispatched to library code the client had picked. A chain through Ecto and DBConnection code ended in an apply/3 call whose module, function, and arguments came from the request body. The result was OS command execution as the BEAM process user. Hex.pm reports that this was exploited against the hosted service on 2026-11-23 (Hex.pm incident post).
The fix rejects any decoded term that contains a map with a __struct__ key and returns HTTP 400.
2. Flaw classification
| Item | Value |
|---|---|
| Primary CWE | CWE-502, Deserialization of Untrusted Data (CAPEC-586, Object Injection, is also listed by the CNA) |
| Attack vector | Network. An unauthenticated HTTP POST with an Erlang external term format body and the application/vnd.hex+erlang content type |
| Impact | OS command execution as the BEAM process user. That user can read the application environment, which per the CNA holds the database URL, storage credentials, and the registry signing key |
| Prerequisites | None. No account, no user interaction. The request must reach the vulnerable endpoint, and some error-reporting path must call inspect on request data or stack-frame arguments |
| Severity | CVSS v3.1 8.8 High (AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H), CVSS v4.0 10.0 Critical (AV:N/AC:L/AT:N/PR:N/UI:N, E:A) — both scored by the CNA; NVD analysis pending |
| Affected | hex.pm from 2016-02-23 to before 2026-11-23. hexpm/hexpm from ab1bbce up to but not including 379b0a2 |
| Exploitation | Exploited against hex.pm on 2026-11-23, per the CNA record and the Hex.pm incident post |
3. Root cause
This is not a single bug. It is a missing check that let several independently reasonable pieces of behavior combine. Each point below follows the CNA technical analysis and the Hex.pm incident post.
3.1 The decoder trusted a “safe” mode too much
HexpmWeb.ErlangFormat.decode/1 calls Plug.Crypto.non_executable_binary_to_term/2 with [:safe]. That mode refuses functions and creating new atoms. It places no restriction on maps. In a release, every module and function name already exists as an atom, so a body can refer to any loaded module without creating new atoms. Hex.pm’s history shows the safety check was removed on 2016-02-23. This matches the start of the affected range.
3.2 The decoded value became request params, before authentication
HexpmWeb.PlugParser.parse/5 returns the decoded term as the body params, and Plug.Parsers merges it into conn.params. The parser sits in the endpoint ahead of the router. No authentication plug has run yet, and the route does not matter.
3.3 A struct is just a map, and protocols dispatch on one key
In Elixir, a struct is a map whose __struct__ key names a module. Protocol dispatch (Inspect, Enumerable, and others) tests only that key. It does not check that the value was created by that module’s own constructor. If the client controls the __struct__ value, it also controls which protocol implementation runs and what data that implementation sees. This is the core of the deserialization flaw: the client chooses which code runs, and the code that runs trusts the struct’s fields.
3.4 Error reporting calls inspect on attacker data
Plug.MethodOverride reads body_params["_method"] on every POST. For a struct, Access.get/3 calls fetch/2 on the named module. With a module that does not define fetch/2, this raises UndefinedFunctionError, and the stack frame holds the attacker’s struct as an argument. Error reporters (Sentry, the Bandit error log, and the JSON log formatter, per the CNA) then call inspect/1 on request data and stack-frame arguments.
3.5 Library code that assumed well-formed structs
Two library behaviors, as described by the CNA and the Hex.pm post, complete the chain:
- The
Inspectimplementation forEcto.Query.DynamicExprenumerates itsbindingfield without checking that it is a list. Enumeration is another protocol call, so a struct placed in that field is dispatched again. - The
Enumerableimplementation ofDBConnection.Streamtakes its connection, query, params, and options from the struct. On an error path, it still runs the:logoption. If that option is a{module, function, args}tuple, the library applies it with the log entry prepended. All three values come from the request.
4. Exploit flow (conceptual)
Each step is described by what it does, not by what is sent. No attack input is given here on purpose.
- Entry point. The attacker sends an unauthenticated POST to any route with the
application/vnd.hex+erlangcontent type. The body is a serialized Erlang term. - Struct smuggling. The decoder accepts the term. Functions and new atoms are blocked, but a map carrying a
__struct__key naming an already-loaded module is allowed. The term becomes the request params. - Forced error.
Plug.MethodOverridereads a key from the params. This fails because the named module has no matching access function. The exception holds the struct in its stack frame. - Error reporting dispatches protocols. The error reporters inspect the struct. The client has chosen the module, so the client has chosen the
Inspectimplementation that runs. That implementation enumerates a field the attacker also controls, which triggers a second protocol dispatch. - Callback abuse. The nested struct reaches the DBConnection streaming code. Its error path invokes a “log” callback specified as module, function, and arguments from the request, via
apply/3. - Impact. The attacker uses this call primitive to reach a standard-library function that in turn runs a chosen call. This executes an OS command as the BEAM user. The HTTP client only sees an ordinary 500 response, because the
Inspectimplementation runs inside a rescue.
- POST any route — unauthenticated, vnd.hex+erlang body
- decoder accepts __struct__ map — into conn.params
- MethodOverride raises error
- error reporter calls inspect — client picks Inspect/Enumerable impls
- log hook apply/3 — MFA from body
- OS command execution
5. Trigger conditions
- Server application: the hexpm server code, either hosted hex.pm or a self-hosted
hexpm/hexpmdeployment that is not yet at379b0a2. The Hex.pm post says the Hex client and other tools are not the vulnerable component. It describes the flaw as being in the hex.pm server. - Input path: the
application/vnd.hex+erlangparser in the endpoint. This path was reachable on every route, before routing and authentication. - Gadget availability: the loaded dependencies must include the Ecto and DBConnection code that supplies the chain. The CNA describes this chain for hexpm’s own dependency set.
- Error reporting: something must call
inspecton request data or stack-frame arguments after the error. The CNA names Sentry, Bandit’s error log, and the JSON log formatter. Whether the chain is reachable without any of them is not confirmed in public sources. - Privileges and interaction: none are required.
- Workaround: the GitHub advisory lists none. Patching is the remedy.
6. Patch analysis
The fix is commit 379b0a2, “Refuse structs in Erlang term request bodies”. It changes lib/hexpm_web/erlang_format.ex and adds tests. The key part of the change:
def decode(binary) do
term = Plug.Crypto.non_executable_binary_to_term(binary, [:safe])
{:ok, term}
if struct?(term) do
{:error, "bad binary_to_term"}
else
{:ok, term}
end 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
defp struct?([head | tail]), do: struct?(head) or struct?(tail)
defp struct?(tuple) when is_tuple(tuple), do: struct?(Tuple.to_list(tuple))
defp struct?(_other), do: falseWhy this breaks the flow. Step 2 of the flow depended on the decoder returning {:ok, term} for any term that passed the [:safe] check. After the change, the term is walked recursively through maps (keys and values), lists, and tuples. If any map has a __struct__ key, decoding returns an error, which the parser turns into a 400 per the CNA. A client can no longer put a struct into the params, so none of the later protocol-dispatch steps are reached. Walking nested values matters. A check on the top-level term alone would miss a struct hidden inside another structure.
Because the check sits in the single decoder used for this content type, it covers every route that accepts it. The Hex.pm post stresses that this closes the entry point only. It lists planned hardening in other libraries so that the chain is also cut further down:
- plug_crypto: document that the decoder is safe only for authenticated payloads, and add an option to reject structs.
- plug: refuse struct values as body params.
- ecto: check that the binding is a list in
Inspect. - db_connection: do not apply
:logcallbacks taken from stream structs (tracked as CVE-2026-133555).
The post describes these as work in progress. Their release status is not confirmed in public sources.
7. Detection & mitigation
Immediate actions
- Hosted hex.pm users: per the Hex.pm post, change your password and reset 2FA. Update your Hex client when the release with the new signing system is available, and until then use only repo.hex.pm, not mirrors.
- Self-hosted hexpm operators: deploy a build that includes
379b0a2and restart all nodes. Treat the environment of any pre-fix server that was exposed to untrusted traffic as potentially exposed. The CNA states that the BEAM user can read the database URL, storage credentials, and the registry signing key. Rotate those credentials. For reference, Hex.pm rotated the credentials the attacker could have read on its own infrastructure, but says it has not yet rotated the registry signing key while a new signing system is built (Hex.pm security incident post). - Check for stragglers: Hex.pm reports that three servers restarted onto the old build during the incident. Confirm that no node, including workers and job servers, still runs an old image.
- Application developers in general: do not pass untrusted input to
binary_to_termor to the “safe” variants and then use the result as params. The “safe” option is not a guarantee of safety. Reject struct maps, or avoid this format for unauthenticated input.
Detection
- Error tracker and logs: Hex.pm says its error tracker recorded an error for each exploit request, and that this is how it detected the attack. Look for exceptions from
Plug.MethodOverrideon POST requests, especiallyUndefinedFunctionErrorwith an unexpected module name. The CNA describes the request as ending in an ordinary 500 response. - Request patterns: look in load balancer or access logs for POSTs with the
application/vnd.hex+erlangcontent type to routes that would not normally accept it, from sources that are not known Hex clients. - Host-side: look for files or processes created by the BEAM user that do not match normal behavior. Hex.pm matched file creation times on servers to request times. Database reads, environment reads, and shell commands are not logged by default, so absence of evidence is weak.
- Other BEAM apps: search for code that decodes client-supplied Erlang terms. Hex.pm found the same class of problem in Ash keyset pagination cursors (CVE-2026-124283, fixed in ash 3.38.0 according to the Hex.pm post).
Isolated practice (local Docker lab)
Reproduce this only in a local Docker lab that is isolated from the internet. Use a network with no outbound access, and use throwaway credentials. Never test against hex.pm or any system you do not own.
Suggested learning goals, with no attack inputs:
- Build a minimal Plug/Phoenix app with a custom body parser that decodes Erlang terms in “safe” mode. Confirm that function values and new atoms are refused, then observe what the check does not cover.
- In
iex, observe howinspect/1andEnumchoose an implementation from the__struct__value of a map. Do this with harmless structs of your own. - Apply the struct-rejecting check from section 6 and confirm that the parser now returns 400.
- Review how your own error reporters (Sentry, log formatters) handle request data, and what code they can reach when they inspect it.