Am I affected?
Description
Improper Input Validation vulnerability in phoenixframework phoenix (Phoenix.Presence) allows an attacker who can join a channel to cause a denial of service via a non-string presence key.
track/3,4 accepts any term as the presence key, such as a JSON object taken from a join payload. The key is converted with to_string/1 only later, in Phoenix.Presence.group/1, which raises Protocol.UndefinedError on a map. group/1 runs whenever presences are listed and when each presence diff is broadcast, together with the application's fetch/2, which can likewise raise on an unexpected key. Once such a key is tracked, every process that lists presences on the topic crashes, typically each channel that joins it, and presence diffs for the topic are lost.
From 1.7.0 the diff runs in a Task.Supervisor.async task linked to the tracker shard, and Phoenix.Presence.handle_info/2 has no clause for its failure. The shard then terminates, taking down every channel and LiveView process tracked on it and erasing presence state for all its topics. Repeated joins exhaust the restart intensity and take down the application supervisor.
This issue affects phoenix: from 1.2.0 before 1.5.16, from 1.6.0-rc.0 before 1.6.18, from 1.7.0-rc.0 before 1.7.25, and from 1.8.0-rc.0 before 1.8.17.
Technical analysis
1. Key accepted. The track/3,4 injected by use Phoenix.Presence passes any term to Phoenix.Tracker.track, which returns {:ok, ref}. The documented pattern Presence.track(socket, name, meta) with name from the join payload lets a client choose a map as the key.
2. Deferred conversion. Phoenix.Presence.group/1 converts each key with to_string/1. It runs in Phoenix.Presence.list/2, in the calling process, and in handle_diff/2 before the application's fetch/2. A map key raises Protocol.UndefinedError there, as does a fetch/2 such as the moduledoc's String.to_integer(key) on a non-numeric key.
3. Topic crash. While the key stays tracked, every list on the topic raises. The documented after_join that pushes Presence.list(socket) therefore crashes each later joiner's channel. Before 1.7.0, handle_diff/2 runs in an unlinked Task.Supervisor.start_child task, so a failing diff only loses that batch of joins and leaves.
4. Shard crash (1.7.0 and later). handle_diff/2 runs the diff in a Task.Supervisor.async task linked to the tracker shard, and Phoenix.Presence.handle_info/2 matches only the task's success reply. The failure terminates the shard (FunctionClauseError), every tracked process linked to it dies, and presence state is wiped. Repeated joins exhaust the supervisor's restart intensity.
Proof of concept
- Run a Phoenix endpoint with a channel whose join reads
namefrom the join payload and then callsMyPresence.track(socket, name, %{online_at: 1}). - Join the topic with 15 clients using string names, and confirm
MyPresence.list(topic)returns 15 entries. - Join once more with the payload
{"name": {"x": 1}}. - The log shows
Protocol.UndefinedErrorfromPhoenix.Presence.group/1, then the shard terminating. All 15 clients receivephx_error, andMyPresence.list(topic)returns 0 entries.
Weaknesses & attack patterns
Weakness
CWE-20
·
Improper Input Validation
in catalog →
MITRE ↗
Attack patterns
CAPEC-153
·
Input Data Manipulation
MITRE ↗
With one channel join an attacker makes the topic's presence unusable: every later join that lists presences crashes, and presence updates stop. From 1.7.0 the same join terminates every channel and LiveView process tracked on the Presence shard and erases presence state for all its topics, and repeating it brings down the application.
Affected — Hex / phoenix Hex.pm ↗ Repository ↗
modules · source files · routines
Affected — GitHub / phoenixframework/phoenix Repository ↗
modules · source files · routines
Workarounds
Validate every presence key before passing it to track/3,4, untrack/2,3 or update/3,4, so that only strings reach the tracker. For a key taken from client input, reject a join whose value is not a binary, or convert it explicitly:
def join("room:" <> _, %{"name" => name}, socket) when is_binary(name) do
send(self(), {:after_join, name})
{:ok, socket}
endA fetch/2 callback must also not raise on any tracked key.
Configurations
The application must use Phoenix.Presence and either track presences under a key influenced by client input (such as a name taken from the channel join payload), or define a fetch/2 callback that can raise on a tracked key. Applications that track only server-controlled string keys and whose fetch/2 cannot raise are not affected.
References
Credits
CVSS breakdown
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
Exploitability
- Attack Vector
- Network
- Attack Complexity
- Low
- Attack Requirements
- Present
- Privileges Required
- None
- User Interaction
- None
Vulnerable System
- Confidentiality
- None
- Integrity
- None
- Availability
- High
Subsequent Systems
- Confidentiality
- None
- Integrity
- None
- Availability
- None