Summary
Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection') vulnerability in elixir-ecto dbconnection allows an attacker to execute arbitrary code via a forged DBConnection.Stream or DBConnection.PrepareStream struct. The Enumerable implementations of both structs in lib/dbconnection.ex run with the options stored in the struct. The :log option accepts a {module, function, arguments} tuple, which DBConnection applies. When code enumerates a forged struct, DBConnection calls the chosen function.
This issue is not exploitable in dbconnection alone. It is, in theory, a vulnerability of the downstream component. The root cause is a component that decodes untrusted input with :erlang.binarytoterm/2 and does not restrict which terms the result contains. The :safe option does not reject structs, and these structs contain only plain terms. Structs of other libraries can possibly lead to the same result, so a component that decodes untrusted terms stays at risk independently of dbconnection. This record exists because the struct was used in attacks on such components.
This issue affects dbconnection: from 1.1.0 before 2.10.3.
Impact
An attacker who can make an application build and enumerate a forged stream struct can call an exported function of a loaded module with chosen arguments in the application's VM.
Configurations
The application, or one of its dependencies, builds Elixir structs from untrusted input (for example with :erlang.binarytoterm/2 or Plug.Crypto.nonexecutablebinarytoterm/2) and then enumerates or inspects the result.