SSE subscribers unbounded — every chat broadcast walks all listeners under one lock
Report
//#What happens
GET /chat/events (api/chat.go:78) calls SubscribeChat() once per connected client. In chat/chat.go:
go func (s ChatStore) Subscribe() (chan Envelope, func()) { ch := make(chan *Envelope, 64) s.listenerMu.Lock() s.listeners = append(s.listeners, ch) // <- no cap, no per-IP limit, nothing s.listenerMu.Unlock() ... }
There is no cap on listeners. And every Store() does this:
go s.listenerMu.Lock() for _, ch := range s.listeners { select { case ch <- env: default: } } s.listenerMu.Unlock()
So the cost of delivering one chat message is O(number of SSE connections on the node), all while holding listenerMu — which every Store() (i.e. every incoming p2p account_chat and every POST /chat/send) also needs.
Auth for /chat/events is a one-time challenge+signature. The read rate limit is 200 req/s sustained, burst 1000 per IP. So one machine can stack up 200 connections per second, each one a permanent listener + goroutine.
Measured impact
I benchmarked the real ChatStore with N subscribers and timed Store():
listeners=0 Store() avg=45ns heap=0.6 MB
listeners=1000 Store() avg=689ns heap=1.3 MB
listeners=10000 Store() avg=5.5µs heap=7.5 MB
listeners=50000 Store() avg=77.7µs heap=36.5 MB
50k connections (reachable in ~4 min from a single IP at the allowed rate) makes every chat broadcast ~1700x slower and serializes all chat ingestion behind listenerMu. Chat delivery for legitimate users degrades linearly while the attacker holds the connections open — and it costs the attacker nothing per message after connect.
Repro
go store := chat.NewChatStore(100) subs := make([]func(), 0, N) for i := 0; i < N; i++ { _, unsub := store.Subscribe() subs = append(subs, unsub) } // now time store.Store(env) — grows linearly with N, see numbers above
End-to-end version: open N GET /chat/events?account=...&challenge=...&sig=...&pub_key=... connections, keep them idle (the 20s ping keeps them alive), then watch /chat/send latency climb.
Related oddity
http.Server is created with WriteTimeout: 60s (cmd/xe/main.go:1458) but SSE connections need to live indefinitely — either the write deadline kills every SSE stream at 60s (making the feature broken for real users) or it's exempted somehow. Might be worth checking while fixing this.
Suggested fix
Cap total listeners (e.g. 256) and reject new SSE connections beyond that; or per-IP SSE connection limit; and/or move broadcast outside the store lock (snapshot the slice, release, then fan out).
This lands under the Track 2 bullet "Chat, SSE and API starvation under many concurrent clients" almost word for word.
Thread
Thanks. This is the same finding as https://bounty.xe.network/XE-0027, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, reply with what differs and we will look again.