Skip to main content
Menu
Advisories

Secret key base exposed in stack trace arguments on wrong-typed Plug.Crypto arguments

GHSA-FFW9-W85G-F2VHPublished Updated GitHub

Description

Every public function in Plug.Crypto checks its argument types in a function-head guard. When a guard fails, the VM raises FunctionClauseError with the actual argument values in the top stack frame. The library's rescue ... reraise blocks and prune_args_from_stacktrace/1 only apply to exceptions raised inside a function body, so they never see these. Both Plug.Cowboy and Bandit write that frame, arguments included, to error logs. If logs are sent to external systems or are stored without encryption, then they may have access to the application's secret key base.

The following functions are reachable with request data:

  • Plug.Crypto.verify/4 with a non-binary, non-nil token prints the secret key base. Phoenix.Token.verify/4 and decrypt/4 (v1.7.21, v1.8.x, main) forward the token argument with only is_binary(salt) guarded, and Plug.Parsers yields a list for token[]=x in a query string and an integer or map for a JSON body, so a controller that passes params["token"] is enough.
  • Plug.Crypto.decrypt/4 with a non-binary token prints the derived 32-byte key: the main clause has no is_binary(token) guard, so the key is derived first and the guard that fails is MessageEncryptor.decrypt/4's.
  • Plug.Crypto.secure_compare/2 with a non-binary operand prints the other operand. Comparing List.first(get_req_header(conn, "x-api-key")) or a param against a configured secret is a common pattern; a request without the header passes nil and the configured secret is logged.

Impact

A reader of application logs or of the error tracker obtains the secret key base (sufficient to mint session cookies and tokens under any salt) or the server-side value an API key is compared against. Triggering it needs one unauthenticated request with a wrong-typed parameter or a missing header. Log and error-tracker access is a second step, but those systems are routinely less protected than application config.

Affected versions

References

GitHub · elixir-plug/plug