Summary
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/hexpmweb/erlangformat.ex decodes the body with Plug.Crypto.nonexecutablebinarytoterm/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.
Details
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.nonexecutablebinarytoterm/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 bodyparams["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.
Impact
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.
Summary
Improper Neutralization of Input During Web Page Generation (XSS or 'Cross-site Scripting') vulnerability in hexpm hexpm/hexpm ('Elixir.HexpmWeb.SharedAuthorizationView' modules) allows Cross-Site Scripting (XSS).
This vulnerability is associated with program files lib/hexpmweb/views/sharedauthorizationview.ex and program routines 'Elixir.HexpmWeb.SharedAuthorizationView':rendergroupedscopes/3.
This issue affects hex.pm: from 2025-10-01 before 2026-01-19; hexpm/hexpm: from 617e44c71f1dd9043870205f371d375c5c4d886d before c692438684ead90c3bcbfb9ccf4e63c768c668a8.
Summary
Incorrect Authorization vulnerability in the OAuth token endpoint in hexpm hexpm allows an API key holding the repositories permission to read another organization's private packages.
When an API key is exchanged for a token through the OAuth clientcredentials grant, validatescopesagainstkey/2 in lib/hexpmweb/controllers/api/oauthcontroller.ex admits a requested scope whenever the key carries the repositories permission and the scope string begins with repository:. The organization name is never resolved against the principal, and expandrepositoriesscope/3 only rewrites the literal repositories scope, so an explicit repository:<name> passes through untouched. Both CDN edges authorize repository access from the token claim without querying the database, so the minted token is read access to that organization's private packages until it expires.
This issue affects hex.pm: from 2025-10-18 before 2026-08-24; hexpm/hexpm: from 71829cb6f6559bcceb1ef4e43a2fb8cdd3af654b before bf0fb9d208f0acfabf7a2f7467c8231659e322a8.
Summary
Incorrect Authorization vulnerability in the OAuth token endpoint in hexpm hexpm allows an API key holding the repositories permission to read another organization's private packages.
When an API key is exchanged for a token through the OAuth clientcredentials grant, validatescopesagainstkey/2 in lib/hexpmweb/controllers/api/oauthcontroller.ex admits a requested scope whenever the key carries the repositories permission and the scope string begins with repository:. The organization name is never resolved against the principal, and expandrepositoriesscope/3 only rewrites the literal repositories scope, so an explicit repository:<name> passes through untouched. Both CDN edges authorize repository access from the token claim without querying the database, so the minted token is read access to that organization's private packages until it expires.
This issue affects hex.pm: from 2025-10-18 before 2026-08-24; hexpm/hexpm: from 71829cb6f6559bcceb1ef4e43a2fb8cdd3af654b before bf0fb9d208f0acfabf7a2f7467c8231659e322a8.
Summary
Insufficient Session Expiration vulnerability in the OAuth token refresh grant in hexpm hexpm allows a user removed from an organization to keep reading its private packages.
expandrepositoriesscope/3 in lib/hexpm/permissions.ex only rewrites the literal repositories scope, so an explicitly granted repository:<org> or docs:<org> scope passes through it untouched. The refresh grant re-derives a new token from the stored grantedscopes, which holds that expanded form, so every refresh reproduces the organization scope without revisiting membership. Because both CDN edges authorize repository access from the token claim without querying the database, an account removed from an organization retains read access for as long as it keeps refreshing, bounded by the 30 day refresh token lifetime rather than the 30 minute access token lifetime.
This issue affects hex.pm: from 2025-10-10 before 2026-08-24; hexpm/hexpm: from 650faa03af511e74c1b3b49ec12d35666b6984c4 before 50cffd206490c49c92d7b63c8505949682abedb0.
Summary
Insufficient Session Expiration vulnerability in OAuth token issuance in hexpm hexpm allows a user whose organization membership or session has ended to keep reading the organization's private packages and their documentation tarballs via a retained refresh token.
generaterefreshtoken/4 in lib/hexpm/oauth/jwt.ex signs the refresh token with the same iss, aud and scope claims as the access token, so it carries the same repository:<org> scopes. The CDN service that serves private repositories verifies the signature and time claims and then authorizes from the scope claim, with no database lookup and no way to tell the two token kinds apart. Removing a member or revoking a session therefore takes effect at the CDN only when the 30 day refresh token expires, instead of after the 30 minute access token lifetime. Access is read-only and limited to organizations the account belonged to when the token was granted.
This issue affects hex.pm: from 2025-10-10 before 2026-09-22; hexpm/hexpm: from 650faa03af511e74c1b3b49ec12d35666b6984c4 before db58cf3a86c7639708ef52ff86de0b4f938e6360.
Details
1. Token issuance
Hexpm.OAuth.JWT.generaterefreshtoken/4 builds its claim set from the same template as generateaccesstoken/4, changing only exp, so a refresh token carries the scope claim of the access token it is issued with. hexpm itself never reads that claim: the refresh grant resolves scopes from the database, and Hexpm.OAuth.Tokens.lookup/3 matches an access token on the jti column and a refresh token on refreshjti, so hexpm's API rejects a refresh token presented as a bearer credential.
2. Edge authorization
The CDN service in front of private repositories consults no database. It verifies the ES256 signature, iss, aud, nbf and exp, then grants access when scope contains repository:<org>. A refresh token sent as Authorization: Bearer passes every check and is authorized like an access token.
3. Effect
Member removal, session revocation and an organization single sign-on session lapsing rely on the 30 minute access token lifetime to take effect at the CDN, because the CDN has no revocation list. A copy of the refresh token extends that window to its 30 day lifetime.
Proof of concept
1. Authenticate a CLI session with mix hex.user auth for an account that is a member of an organization with private packages. ~/.hex/hex.config then holds an access token and a refresh token. 2. Copy the refresh token out of that file. 3. Remove the account from the organization, or revoke the session. 4. Request https://repo.hex.pm/repos/<org>/tarballs/<package>-<version>.tar with the header Authorization: Bearer <refresh token>. 5. The CDN serves the tarball until the refresh token's 30 day expiry, while the access token from the same file stops working within 30 minutes.
Impact
A user removed from an organization, or anyone holding a copy of a revoked session's refresh token, can keep downloading that organization's private packages and their documentation tarballs for up to 30 days after access was withdrawn.