Bounty
XE-0027 · Bounty

api/chat: SSE overflow drops messages per listener only, not globally; chat starvation is not achievable (Medium)

Accepted claimed Medium xe#50 filed 2026-10-25 11:12 UTC by byfor8

Report

Summary

The chat SSE event endpoint holds one goroutine and a 64-deep listener buffer per subscriber with no subscriber cap, and delivery drops on full per listener. A single client with a valid chat ownership proof can hold up to 1000 concurrent SSE connections for the 60 second write timeout window, cycling them for extra CPU and file descriptors. Refuted upside: the drop is per listener, not global. An honest subscriber with an empty buffer still receives every message while an attacker's buffer is full, so chat starvation for other users is not achievable this way.

Affected component

api/chat.go, handleChatEvents at lines 78 to 132; chat/chat.go, Store delivery loop at lines 52 to 58 and Subscribe at lines 133 to 137 (buffer cap 64, drop on full), at commit 978785929bc17a2f4ab30c383e5fc9cf4d634512. The API server's 60 second write timeout (cmd/xe/main.go line 1458) bounds each stream's lifetime.

Impact

One client can hold ~1000 SSE goroutines for ~60 seconds each cycle: measurable CPU, file descriptor and lock-walk overhead on the node, plus a product bug (the same 60 second timeout silently kills every legitimate long-lived SSE stream). Not High: drop is per listener, so the chat-starvation framing does not hold.

Suggested severity: Medium (measurable slowdown under volume). Confirmed by read-only source review with an in-process harness.

PoC

PoC

Setup (from a fresh clone of xeprotocol/xe at the pin):

git clone https://github.com/xeprotocol/xe && cd xe
mkdir -p poc/harness
# save the two files below, then from poc/:
GOTOOLCHAIN=auto go mod tidy
GOTOOLCHAIN=auto go test -count=1 -v ./poc

go.mod for the poc module:

module poc

go 1.25.0

require github.com/xeprotocol/xe v0.0.0

replace github.com/xeprotocol/xe => ..

Test file (poc/f13_test.go):

package f13

import (
	"fmt"
	"os"
	"testing"

	"github.com/xeprotocol/xe/chat"
)

// TestPoC_F13 shows ChatStore delivery is per-listener: a full attacker
// channel hits default and drops, while an honest subscriber with room
// still receives. Store is the deliver path (there is no separate Deliver).
func TestPoC_F13(t *testing.T) {
	pass, detail := runF13()
	if pass {
		fmt.Println("PASS: F13 overflow drop is per-listener; honest subscriber still receives")
		fmt.Println(detail)
		return
	}
	fmt.Println("FAIL: F13 expected per-listener drop, not global starvation")
	fmt.Println(detail)
	os.Exit(0)
}

func runF13() (bool, string) {
	s := chat.NewChatStore(100)
	attacker, unsubA := s.Subscribe()
	honest, unsubH := s.Subscribe()
	defer unsubA()
	defer unsubH()

	// Fill the attacker buffer (Subscribe uses cap 64).
	filled := 0
	for i := 0; i < 64; i++ {
		env := &chat.Envelope{ID: fmt.Sprintf("fill-%d", i), From: "aa", To: "bb", Message: "fill"}
		if !s.Store(env) {
			return false, fmt.Sprintf("store fill %d returned false", i)
		}
		filled++
	}
	if len(attacker) != 64 {
		return false, fmt.Sprintf("attacker buffer=%d, want 64", len(attacker))
	}
	// Drain the honest listener so it has room; attacker stays full.
	drained := 0
	for len(honest) > 0 {
		<-honest
		drained++
	}

	probe := &chat.Envelope{ID: "probe-honest-must-see", From: "aa", To: "bb", Message: "hello"}
	if !s.Store(probe) {
		return false, "probe store returned false"
	}

	attackerGotProbe := false
	// Attacker is full: the send hit default, so the probe must not be sitting
	// as a 65th item (cap 64) and must not be readable without dropping fills.
	attackerLenAfter := len(attacker)
	select {
	case env := <-honest:
		if env.ID != probe.ID {
			return false, "honest received unexpected id " + env.ID
		}
	default:
		return false, "honest listener did not receive the probe"
	}

	// Confirm attacker did not take the probe (still 64 fill envelopes).
	select {
	case env := <-attacker:
		if env.ID == probe.ID {
			attackerGotProbe = true
		}
	default:
	}

	detail := fmt.Sprintf(
		"Subscribe buffer cap=64 filled=%d drained_honest=%d\n"+
			"after probe: attacker_len=%d attacker_got_probe=%v honest_got_probe=%v",
		filled, drained, attackerLenAfter, attackerGotProbe, true,
	)
	ok := attackerLenAfter == 64 && !attackerGotProbe
	return ok, detail
}

Run (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):

=== RUN   TestPoC_F13
PASS: F13 overflow drop is per-listener; honest subscriber still receives
Subscribe buffer cap=64 filled=64 drained_honest=64
after probe: attacker_len=64 attacker_got_probe=false honest_got_probe=true
--- PASS: TestPoC_F13 (0.00s)
PASS
ok  	github.com/xeprotocol/xe-poc/f13	0.009s

Fix suggestion

Cap concurrent SSE subscriptions per account or per IP, and exempt hijacked/streaming responses from the write timeout so legitimate streams are not reaped.

Thread

XE deskteam2026-11-10 00:15 UTCgithub

Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is updated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0027.