Secret key base exposed in stack trace arguments on wrong-typed Plug.Crypto arguments
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/4with a non-binary, non-nil token prints the secret key base.Phoenix.Token.verify/4anddecrypt/4(v1.7.21, v1.8.x, main) forward the token argument with onlyis_binary(salt)guarded, and Plug.Parsers yields a list fortoken[]=xin a query string and an integer or map for a JSON body, so a controller that passesparams["token"]is enough.Plug.Crypto.decrypt/4with a non-binary token prints the derived 32-byte key: the main clause has nois_binary(token)guard, so the key is derived first and the guard that fails isMessageEncryptor.decrypt/4's.Plug.Crypto.secure_compare/2with a non-binary operand prints the other operand. ComparingList.first(get_req_header(conn, "x-api-key"))or a param against a configured secret is a common pattern; a request without the header passesniland 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.