#2

[HIGH] Wildcard Nickname Erases Cluster Session State

OpenxlabMemberopened 3mo ago

Audited commit: bfa9d9f43c2fc0a6c008544ca6ea90ab2a4dbc57

Classification

  • Severity: High
  • Confidence: Certain
  • Type: Attacker-triggered denial of service and integrity destruction through unintended wildcard matching
  • Original classification: Authorization bypass
  • Scope: PostgreSQL-backed deployments

Affected Locations

  • src/pg.zig:697-704
  • Specifically, Conn.deleteSession and its three nickname-based DELETE statements

Summary

deleteSession treated a client-controlled nickname as an SQL ILIKE pattern. PostgreSQL interprets _ as any single character and % as any sequence, even when the pattern is supplied through a parameterized query.

An attacker able to connect with underscore-containing nicknames could disconnect and delete session, share, and channel-membership rows belonging to unrelated users. Repeating the operation with nicknames containing one through nineteen underscores covers every normally accepted nickname length under the default maximum, causing cluster-wide availability and integrity loss.

Preconditions

  • The deployment uses PostgreSQL as its source of truth.
  • Remote clients can choose nicknames containing _ or %.
  • The attacker disconnects after the crafted nickname has been stored.
  • Although the one-shot % nickname is blocked by existing validation, underscore-containing nicknames remain sufficient for exploitation.

Proof

The disconnect path passes the client’s stored nickname to deleteSession. The vulnerable implementation executes:

self.execParams("DELETE FROM sessions WHERE nick ILIKE $1", &vals) catch {};
self.execParams("DELETE FROM shares WHERE nick ILIKE $1", &vals) catch {};
self.execParams("DELETE FROM channel_members WHERE nick ILIKE $1", &vals) catch {};

Parameterization prevents SQL syntax injection but does not escape LIKE metacharacters. A nickname of _____ is therefore a five-character wildcard pattern and deletes every five-character nickname’s rows from all three tables.

With the default 19-character nickname maximum, an attacker can cycle through nicknames containing 1–19 underscores. This bounded sequence matches and removes all normally accepted nickname lengths. The deleted state is amplified across cluster behavior:

  1. sessions is the cluster source of connected-user state.
  2. shares stores each user’s advertised files.
  3. channel_members stores cluster channel membership.
  4. PostgreSQL-backed searches join shares to sessions.
  5. Cross-replica routing, visibility, membership listings, and searches depend on those rows.

Consequently, a small bounded number of attacker disconnects destroys state for many unrelated connected users cluster-wide.

Why This Is A Real Bug

deleteSession is intended to remove only the disconnecting client’s identity state. ILIKE instead grants pattern semantics to that identity, expanding one attacker-controlled nickname into deletion authority over unrelated rows.

The impact is directly observable: connected victims become unavailable or invisible across replicas, their shares disappear from searches, and their channel memberships are removed. This is practical remote denial of service and integrity destruction, not merely an incorrect query result.

Fix Requirement

Use exact case-insensitive equality for nickname identity comparisons in all three deleteSession statements. Nicknames must be treated as complete identifiers, never as wildcard patterns.

Patch Rationale

The patch replaces nick ILIKE $1 with:

lower(nick) = lower($1)

This preserves the intended case-insensitive nickname matching while removing the special meaning of % and _. A disconnect can therefore delete only rows whose complete nickname equals the disconnecting client’s nickname, ignoring case.

Residual Risk

None

Patch suggestion

diff --git a/src/pg.zig b/src/pg.zig
index ece45a7..0d4ba35 100644
--- a/src/pg.zig
+++ b/src/pg.zig
@@ -698,9 +698,9 @@ pub const Conn = struct {
         const nick_z = self.allocator.dupeZ(u8, nick) catch return;
         defer self.allocator.free(nick_z);
         const vals = [_]?[*:0]const u8{nick_z.ptr};
-        self.execParams("DELETE FROM sessions WHERE nick ILIKE $1", &vals) catch {};
-        self.execParams("DELETE FROM shares WHERE nick ILIKE $1", &vals) catch {};
-        self.execParams("DELETE FROM channel_members WHERE nick ILIKE $1", &vals) catch {};
+        self.execParams("DELETE FROM sessions WHERE lower(nick) = lower($1)", &vals) catch {};
+        self.execParams("DELETE FROM shares WHERE lower(nick) = lower($1)", &vals) catch {};
+        self.execParams("DELETE FROM channel_members WHERE lower(nick) = lower($1)", &vals) catch {};
     }
 
     pub fn getSession(self: *Conn, nick: []const u8) ?Session {

Activity

0

No activity yet.