CVE-2026-133555 — Elixir-ecto Db Connection (2.10.3) — CWE-470
Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection') vulnerability in elixir-ecto db_connection allows an attacker to execute arbitrary code via a forged DBConnection.Stream or DBConnection.PrepareStream struct. The Enumerable implementations of both structs in lib/db_connection.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 db_connection alone. It is, in theory, a vulnerability of the downstream component. The root cause is a component that decodes untrusted input with :erlang.binary_to_term/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 db_connection. This record exists because the struct was used in attacks on such components. This issue affects db_connection: from 1.1.0 before 2.10.3.
Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection') vulnerability in elixir-ecto db_connection allows an attacker to execute arbitrary code via a forged DBConnection.Stream or DBConnection.PrepareStream struct. The Enumerable implementations of both structs in lib/db_connection.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 db_connection alone. It is, in theory, a vulnerability of the downstream component. The root cause is a component that decodes untrusted input with :erlang.binary_to_term/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 db_connection. This record exists because the struct was used in attacks on such components. This issue affects db_connection: from 1.1.0 before 2.10.3.
🎯 What is this vulnerability?
Technical flaw
The vulnerability is a classic unsafe reflection (CWE‑470) in the elixir‑ecto:db_connection library.
DBConnection.StreamandDBConnection.PrepareStreamstructs expose an:logoption that accepts a{module, function, arguments}tuple.- The library’s
Enumerableimplementation for these structs simply calls the supplied function when the struct is enumerated. - An attacker can forge a struct that contains a malicious
:logtuple. - If a downstream component (e.g., an Elixir web framework, a database driver, or any code that blindly enumerates a struct received from an untrusted source) deserialises the struct with
:erlang.binary_to_term/2without validating the term type, the malicious function will be executed with the privileges of the running process.
Missing checks
1. Input validation – The library does not restrict the shape of the struct it accepts; it trusts that the struct was created by a legitimate caller.
2. Deserialization safety – The downstream component uses :erlang.binary_to_term/2 with the :safe flag, which does not reject structs.
3. Authorization – No check that the caller is authorised to specify arbitrary logging callbacks.
Because the vulnerability is in a dependency that is only a data‑transport layer, it is not directly exploitable by itself; the impact materialises only when a downstream component consumes the forged struct.
⚡ Attack Chain
Below is a realistic, step‑by‑step chain that an attacker could use against a typical Elixir/Phoenix application that uses elixir‑ecto:db_connection (v1.1.0‑v2.10.2) and does not validate incoming terms.
| Step | Description | Technical Detail |
|---|---|---|
| 1. Discovery & Reconnaissance | Identify the target application and its dependencies. | • Scan the public repository or the running process for mix.exs or rebar.config.<br>• Use mix deps.get output or mix deps.tree to confirm elixir-ecto:db_connection version < 2.10.3. |
| 2. Crafting a malicious struct | Build a binary that represents a forged DBConnection.Stream or DBConnection.PrepareStream struct with a malicious :log callback. | ``elixir\n# Build a struct that will be deserialized by the victim\nstream = %DBConnection.Stream{\n log: {MyMaliciousModule, :execute, [\"/bin/sh\"]}\n}\n# Serialize to a binary that can be sent over the network\nbinary = :erlang.term_to_binary(stream, [:compressed])\n`\nThe binary can be embedded in a HTTP request body, a WebSocket frame, or any other transport that the downstream component accepts. |
| 3. Delivery | Send the binary to the vulnerable endpoint. | *Illustrative example* – suppose the application exposes an endpoint /api/receive that accepts a binary payload and immediately deserialises it: <br>`bash\ncurl -X POST \\\n -H "Content-Type: application/octet-stream" \\\n --data-binary @payload.bin \\\n http://target.example.com/api/receive\n`\nIf the endpoint does not perform any validation, the binary will be passed to :erlang.binary_to_term/2. |
| 4. Deserialization & Execution | The downstream component calls :erlang.binary_to_term(binary, [:safe]). Because :safe does not reject structs, the forged struct is reconstructed. The Enumerable implementation of DBConnection.Stream then iterates over the struct, calling apply(MyMaliciousModule, :execute, ["/bin/sh"]). | The malicious module is executed with the privileges of the application process (typically www-data` or the user running the BEAM VM). |
| 5. Post‑exploitation | The attacker now has a shell or can run arbitrary code. | • If the malicious module spawns a shell, the attacker can pivot to other services.<br>• If the module writes a web‑shell file to the public directory, the attacker can maintain persistence.<br>• The attacker can exfiltrate data or modify database entries. |
PoC (Illustrative)
# attacker side
defmodule PoC do
def run do
# 1. Build malicious struct
stream = %DBConnection.Stream{
log: {MyMaliciousModule, :execute, ["/bin/sh"]} # arbitrary payload
}
# 2. Serialize
bin = :erlang.term_to_binary(stream, [:compressed])
# 3. Send to target (replace URL with real endpoint)
HTTPoison.post!("http://target.example.com/api/receive",
bin,
[{"Content-Type", "application/octet-stream"}])
end
endNOTE: The exact endpoint (/api/receive) and the transport mechanism are illustrative. The real target may use a different route or a WebSocket channel. The key is that the payload is a binary that the victim will deserialize with:erlang.binary_to_term/2.
🌍 Real World Impact
| Impact | CVSS 4.0 Component | Explanation |
|---|---|---|
| Confidentiality | VC:H | Arbitrary code execution can read any file the process can access, including secrets, database credentials, or user data. |
| Integrity | VI:H | The attacker can modify database rows, configuration files, or code, leading to data tampering. |
| Availability | VA:H | The malicious code could crash the BEAM VM, kill processes, or consume resources, causing denial of service. |
| Scope | SC:H | The vulnerability can affect other components that depend on db_connection (e.g., Phoenix, Ecto adapters). |
| Impact on Users | SI:H | Users may see corrupted data or be redirected to malicious content. |
| Impact on System | SA:H | System-wide compromise if the process runs with elevated privileges. |
Practical consequences
🛡️ Remediation & Mitigation
Affected Versions
elixir-ecto:db_connection 1.1.0 – 2.10.2 (inclusive). Patch Recommendation
1. Upgrade theelixir-ecto:db_connection dependency to ≥ 2.10.3.mix deps.update db_connection2. Verify that the lockfile (mix.lock) reflects the new version.
Workarounds (if upgrade is not immediately possible)
| Mitigation | How to Apply |
|---|---|
| Input validation | In any module that receives binary data from untrusted sources, add a whitelist check before calling :erlang.binary_to_term/2. For example: <br>``elixir\ncase :erlang.binary_to_term(bin, [:safe]) do\n %DBConnection.Stream{} = _ -> :ok\n _ -> raise \"Unexpected term\"\nend\n` |
| Disable enumeration | If the application never needs to enumerate DBConnection.Stream structs, remove the Enumerable implementation or guard it with a feature flag. |
Restrict :log option | Override the :log option to a known safe callback or reject any tuple that is not in a predefined whitelist. |
Use :erlang.binary_to_term/2 with :safe and :strict | While :safe does not reject structs, you can combine it with a custom validation step to reject any struct that is not explicitly allowed. |
| WAF / ModSecurity | Add a rule that blocks requests containing the byte pattern of a serialized DBConnection.Stream struct. Example (ModSecurity): <br>`SecRule REQUEST_BODY "@rx \x00\x01\x02\x03" "id:1001,phase:2,deny,msg:'Suspicious serialized struct'"`` |
| Access restrictions | Ensure that only authenticated and authorised users can reach endpoints that accept binary payloads. |
Detection
| Indicator | Log Pattern | How to Detect |
|---|---|---|
| Binary payloads | POST /api/receive HTTP/1.1 with Content-Type: application/octet-stream | Look for application/octet-stream in request headers. |
| Deserialization calls | :erlang.binary_to_term in stack traces | Enable BEAM tracing or use :observer to capture calls. |
| Unexpected module execution | Logs from MyMaliciousModule.execute/1 | Search for custom module names or suspicious function calls. |
| Process crashes | EXIT messages or :erlang.error logs | Monitor BEAM VM logs for abnormal exits. |
⚠️ Urgency
elixir-ecto:db_connection < 2.10.3. If an upgrade cannot be performed within 24 h, apply the input‑validation workaround and restrict the affected endpoints to authenticated users only.Bottom line: The flaw is a classic unsafe reflection in a dependency that is only a data‑transport layer. An attacker who can send a crafted binary to a downstream component that blindly deserialises it can execute arbitrary code with the application’s privileges. Upgrade to 2.10.3 or higher, or enforce strict validation of incoming terms.
[🤖 CVE Professor AI Security Engine]
FOFA Query