{"id":"EEF-CVE-2026-105963","summary":"Secret key base exposed in stack trace arguments on wrong-typed Plug.Crypto arguments","details":"## Summary\n\nExternally-Generated Error Message Containing Sensitive Information vulnerability in `plug_crypto` in elixir-plug plug_crypto allows an unauthenticated remote attacker to expose the secret key base through application logs via a wrong-typed argument. Every public function in `Plug.Crypto` validates argument types in a function-head guard. A failed guard makes the Erlang VM raise `FunctionClauseError` with the actual argument values in the top stack frame, so the secret key base, a derived key, or the value an API key is compared against lands in that frame. The library's `rescue` blocks and `Plug.Crypto.prune_args_from_stacktrace/1` only reach exceptions raised inside a function body, so they never see a guard failure. Plug.Cowboy and Bandit write the frame to the error log and attach it as `crash_reason` Logger metadata, which error trackers forward.\n\nTwo entry points take request data. `Plug.Crypto.verify/4` exposes the secret key base when the token is neither a binary nor nil, which `Phoenix.Token.verify/4` reaches because it forwards the token unguarded. `Plug.Crypto.secure_compare/2` exposes the other operand when one side is not a binary, as happens when a missing request header yields nil. Reading the leaked value needs separate access to the logs or the error tracker, so the request alone does not disclose the secret to the attacker.\n\nThis issue affects plug: from 1.6.3 before 1.7.0; plug_crypto: from 1.0.0 before 2.2.1.\n\n## Details\n\n**1. Type checks in function-head guards.** Every public function in `Plug.Crypto` validates its arguments in a head guard, for example `secure_compare/2` with `when is_binary(left) and is_binary(right)` and `verify/4` with `when is_binary(key_base) and is_binary(salt) and is_binary(token)`.\n\n**2. The VM builds the error, not the library.** When no clause matches, the Erlang VM raises `FunctionClauseError` and the top stack frame holds the actual argument values. The library's `rescue ... reraise` blocks and `Plug.Crypto.prune_args_from_stacktrace/1` only apply to exceptions raised inside a function body, so a guard failure never reaches them. In `plug_crypto` the same commit that added `prune_args_from_stacktrace/1` also added these guards.\n\n**3. Which value leaks.** `verify/4` and `sign/4` put the secret key base in the frame. `decrypt/4` has no `is_binary(token)` guard on its main clause, so the key is derived first and the failing guard belongs to `MessageEncryptor.decrypt/4`, placing the derived 32-byte key in the frame. `secure_compare/2` places the other operand in the frame, which is the server-side secret when a request value is nil.\n\n**4. The frame reaches logs and error trackers.** Plug.Cowboy and Bandit write the formatted frame, arguments included, to the error log and attach it as `crash_reason` Logger metadata. Error trackers forward it; Sentry's handler sends crash reports by default and serializes frame arguments as `vars`.\n\n## Proof of concept\n\n1. Run an application that depends on `plug_crypto` and exposes a route calling `Phoenix.Token.verify(secret_key_base, \"user auth\", conn.params[\"token\"])`, plus a route calling `Plug.Crypto.secure_compare(List.first(get_req_header(conn, \"x-api-key\")), api_key)`.\n2. Send `GET /verify?token[]=x`. `Plug.Parsers` yields a list for the bracket syntax, so the token argument is a list.\n3. Observe the 500 response and read the error log. The top frame prints `Plug.Crypto.verify(\"SECRET_KEY_BASE_...\", \"user auth\", [\"x\"], [])` with the secret key base in full, and the same frame is attached as `crash_reason` Logger metadata.\n4. Send `GET /api` with no `x-api-key` header. The header lookup yields nil, and the frame prints `Plug.Crypto.secure_compare(nil, \"\u003cconfigured API key\u003e\")`.\n5. A JSON body of `{\"token\": 123}` to the first route gives the same result with an integer argument.\n\n## Impact\n\nAn unauthenticated attacker sends one request with a wrong-typed parameter, or omits a header, and the secret key base or the compared secret is written into the application log and into `crash_reason` metadata forwarded to error trackers. Anyone who can read those logs then holds a key sufficient to mint session cookies and tokens under any salt.\n\n## Workarounds\n\nCheck argument types in the calling code before entering `Plug.Crypto`, so no head guard ever fails. Pass a token to `Phoenix.Token.verify/4`, `Phoenix.Token.decrypt/4`, `Plug.Crypto.verify/4` or `Plug.Crypto.decrypt/4` only when `is_binary(token)` holds, and treat anything else as an invalid token. Call `Plug.Crypto.secure_compare/2` only when both operands are binaries, treating a missing header or parameter as a failed comparison rather than passing nil.\n\nWhere the leaked value matters more than the crash, configuring the error tracker to drop stack-frame arguments also keeps the secret out of the forwarded report. For Sentry this means not sending `vars` with the crash report. This narrows exposure but leaves the value in the local error log.\n\n## Configurations\n\nRequest-data reachability needs an application that passes unvalidated request data into `Plug.Crypto`. Either a controller or plug that hands `params[\"token\"]` to `Phoenix.Token.verify/4` or `Phoenix.Token.decrypt/4`, where `Plug.Parsers` yields a list for `token[]=x` in a query string and an integer or a map for a JSON body, or a call to `Plug.Crypto.secure_compare/2` on a value that can be nil, such as `List.first(get_req_header(conn, \"x-api-key\"))` compared against a configured secret. Disclosure of the leaked value additionally needs read access to the application logs or to an error tracker that receives `crash_reason` metadata. The remaining affected functions require direct misuse by application code and have no request-data trigger.","aliases":["CVE-2026-105963","GHSA-ffw9-w85g-f2vh"],"modified":"2026-10-23T10:10:50.206216545Z","published":"2026-10-23T09:56:58.885Z","database_specific":{"capec_ids":["CAPEC-54"],"cpe_ids":["cpe:2.3:a:elixir-plug:plug:*:*:*:*:*:*:*:*","cpe:2.3:a:elixir-plug:plug_crypto:*:*:*:*:*:*:*:*"],"cwe_ids":["CWE-532"]},"references":[{"type":"ADVISORY","url":"https://github.com/elixir-plug/plug/security/advisories/GHSA-ffw9-w85g-f2vh"},{"type":"WEB","url":"https://cna.erlef.org/cves/CVE-2026-105963.html"},{"type":"WEB","url":"https://github.com/elixir-plug/plug/commit/56000c33d8a0a2fbac491f8be06b9c5112bc2276"},{"type":"FIX","url":"https://github.com/elixir-plug/plug/commit/aeaa90e76b73ea90c3ecca9aae16fce71bd2a8d4"},{"type":"WEB","url":"https://github.com/elixir-plug/plug_crypto/commit/2d078b7b8264c565f0ff71235c515f4f46882dcf"},{"type":"FIX","url":"https://github.com/elixir-plug/plug_crypto/commit/981887493dada0fce7003c61861c00dfbb0fc8c5"},{"type":"PACKAGE","url":"https://hex.pm/packages/plug"},{"type":"PACKAGE","url":"https://hex.pm/packages/plug_crypto"}],"affected":[{"package":{"name":"plug","ecosystem":"Hex","purl":"pkg:hex/plug"},"ranges":[{"type":"SEMVER","events":[{"introduced":"1.6.3"},{"fixed":"1.7.0"}]}],"versions":["1.6.3","1.6.4"],"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-105963.json"}},{"package":{"name":"plug_crypto","ecosystem":"Hex","purl":"pkg:hex/plug_crypto"},"ranges":[{"type":"SEMVER","events":[{"introduced":"1.0.0"},{"fixed":"2.2.1"}]}],"versions":["1.0.0","1.1.0","1.1.1","1.1.2","1.2.0","1.2.1","1.2.2","1.2.3","1.2.4","1.2.5","2.0.0","2.1.0","2.1.1","2.2.0"],"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-105963.json"}},{"ranges":[{"type":"GIT","repo":"https://github.com/elixir-plug/plug","events":[{"introduced":"56000c33d8a0a2fbac491f8be06b9c5112bc2276"}]}],"versions":["v1.6.4","v1.6.3"],"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-105963.json"}},{"ranges":[{"type":"GIT","repo":"https://github.com/elixir-plug/plug_crypto","events":[{"introduced":"2d078b7b8264c565f0ff71235c515f4f46882dcf"},{"fixed":"981887493dada0fce7003c61861c00dfbb0fc8c5"}]}],"versions":["v2.2.0","v2.1.1","v2.1.0","v2.0.0","v1.2.5","v1.2.4","v1.2.2","v1.2.1","v1.2.0","v1.1.2","v1.1.1","v1.1.0","v1.0.0"],"database_specific":{"source":"https://cna.erlef.org/osv/EEF-CVE-2026-105963.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V4","score":"CVSS:4.0/AV:N/AC:L/AT:N/PR:H/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N"}],"credits":[{"name":"Neil Berkman","type":"REPORTER"},{"name":"Neil Berkman","type":"FINDER"},{"name":"Neil Berkman","type":"REMEDIATION_DEVELOPER"},{"name":"Jonatan Männchen / EEF","type":"COORDINATOR"},{"name":"José Valim","type":"REMEDIATION_VERIFIER"}]}