#3

[HIGH] Unauthorized Users Can Overwrite Channel Topics

OpenxlabMemberopened 3mo ago

Audited commit: bfa9d9f43c2fc0a6c008544ca6ea90ab2a4dbc57

Classification

  • Type: Authorization bypass
  • Severity: High
  • CWE: CWE-862 — Missing Authorization
  • Confidence: Certain

Affected Locations

  • src/handlers.zig:1457-1492 — topic accepts and persists topic changes without authorization.
  • src/handlers.zig:1715 — PRIVMSG ChanServ topic ... dispatches ordinary user requests as tags.server_topic.

Summary

Any logged-in user can overwrite the topic of a known existing channel, even when the user is not a channel member or operator. Default configuration permits login with a fresh, unregistered nickname, so preexisting account credentials are not required.

The original pre-login/server-impersonation characterization was not reproduced. The confirmed issue is an authorization bypass reachable through an ordinary user session.

Preconditions

  • The attacker can establish an ordinary user session.
  • The attacker knows the name of an existing channel.
  • Default deployments allow a fresh, unregistered nickname; registered-only deployments require valid user credentials.

Proof

  1. privmsg accepts messages from authenticated users through popUser.
  2. A message addressed to ChanServ is forwarded to chanserv.
  3. chanserv maps the topic command to tags.server_topic and calls dispatch.
  4. dispatch routes tags.server_topic directly to topic.
  5. topic resolves the attacker-supplied channel and, when replacement text is present, performs no membership, operator, moderator, or channel_topic_any authorization check.
  6. The function frees the existing topic and assigns the attacker-controlled replacement at src/handlers.zig:1480.
  7. The replacement is then persisted to PostgreSQL, broadcast to local channel members, published to other replicas, and relayed to peer servers.

A logged-in nonmember can therefore submit the equivalent of:

PRIVMSG ChanServ topic #existing-channel replacement text

and replace that channel’s topic.

Why This Is A Real Bug

Channel topic policy is represented by types.channel_topic_any, while privileged channel actions elsewhere use membership and isChanOp checks. The vulnerable mutation enforces none of these controls.

This is not a display-only discrepancy: the attacker’s text replaces authoritative in-memory state and is subsequently persisted and distributed. The impact is a durable, network-visible integrity violation affecting channels the attacker does not control.

Fix Requirement

Topic mutation must be limited to:

  • authenticated server connections; or
  • authenticated channel members when channel_topic_any is enabled; or
  • authenticated channel operators or moderators when arbitrary-member topic changes are disabled.

Unknown connections, unauthenticated users, and nonmembers must not reach the mutation.

Patch Rationale

The patch places authorization immediately before the first state mutation:

  • .server connections remain accepted for trusted synchronization.
  • Non-server connections must be authenticated .user connections with an attached User.
  • findChanUser requires channel membership.
  • If channel_topic_any is unset, isChanOp requires operator or moderator authority.
  • Existing topic queries remain unaffected because the check applies only when replacement text is present.

This protects the in-memory assignment and every downstream persistence, broadcast, publication, and relay operation.

Residual Risk

None

Patch suggestion

diff --git a/src/handlers.zig b/src/handlers.zig
index 0807d72..7e5f179 100644
--- a/src/handlers.zig
+++ b/src/handlers.zig
@@ -1474,6 +1474,12 @@ fn topic(s: *Server, con: *Connection, pkt: []const u8) void {
         s.sendCmd(con, tags.server_topic, "{s} {s}", .{ chan.name, chan.topic });
         return;
     }
+    if (con.class != .server) {
+        if (con.class != .user) return;
+        const user = con.user orelse return;
+        if (findChanUser(chan, user) == null) return denied(s, con);
+        if (chan.flags & types.channel_topic_any == 0 and !isChanOp(chan, user)) return denied(s, con);
+    }
     var topic_text = chan_a.rest;
     if (s.cfg.max_topic > 0 and topic_text.len > @as(usize, @intCast(s.cfg.max_topic)))
         topic_text = topic_text[0..@intCast(s.cfg.max_topic)];

Activity

0

No activity yet.