{"id":"XE-0027","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"50","source_url":"https://github.com/xeprotocol/xe/issues/50","reporter_id":13,"title":"api/chat: SSE overflow drops messages per listener only, not globally; chat starvation is not achievable (Medium)","area":"node-api","claimed_tier":"medium","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:16.621309+00:00","updated_at":"2026-11-10T11:38:16.814648+00:00","source_created_at":"2026-10-25T11:12:22+00:00","told_at":"2026-11-10T00:15:25+00:00","status_changed_at":"2026-10-29T14:04:12.216995+00:00","url":"https://bounty.xe.network/XE-0027","body":"## Summary\nThe 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.\n\n## Affected component\napi/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.\n\n## Impact\nOne 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.\n\nSuggested severity: Medium (measurable slowdown under volume). Confirmed by read-only source review with an in-process harness.\n\n## PoC\n## PoC\n\nSetup (from a fresh clone of xeprotocol/xe at the pin):\n\n```\ngit clone https://github.com/xeprotocol/xe && cd xe\nmkdir -p poc/harness\n# save the two files below, then from poc/:\nGOTOOLCHAIN=auto go mod tidy\nGOTOOLCHAIN=auto go test -count=1 -v ./poc\n```\n\ngo.mod for the poc module:\n\n```\nmodule poc\n\ngo 1.25.0\n\nrequire github.com/xeprotocol/xe v0.0.0\n\nreplace github.com/xeprotocol/xe => ..\n```\n\n**Test file** (`poc/f13_test.go`):\n\n```go\npackage f13\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"testing\"\n\n\t\"github.com/xeprotocol/xe/chat\"\n)\n\n// TestPoC_F13 shows ChatStore delivery is per-listener: a full attacker\n// channel hits default and drops, while an honest subscriber with room\n// still receives. Store is the deliver path (there is no separate Deliver).\nfunc TestPoC_F13(t *testing.T) {\n\tpass, detail := runF13()\n\tif pass {\n\t\tfmt.Println(\"PASS: F13 overflow drop is per-listener; honest subscriber still receives\")\n\t\tfmt.Println(detail)\n\t\treturn\n\t}\n\tfmt.Println(\"FAIL: F13 expected per-listener drop, not global starvation\")\n\tfmt.Println(detail)\n\tos.Exit(0)\n}\n\nfunc runF13() (bool, string) {\n\ts := chat.NewChatStore(100)\n\tattacker, unsubA := s.Subscribe()\n\thonest, unsubH := s.Subscribe()\n\tdefer unsubA()\n\tdefer unsubH()\n\n\t// Fill the attacker buffer (Subscribe uses cap 64).\n\tfilled := 0\n\tfor i := 0; i < 64; i++ {\n\t\tenv := &chat.Envelope{ID: fmt.Sprintf(\"fill-%d\", i), From: \"aa\", To: \"bb\", Message: \"fill\"}\n\t\tif !s.Store(env) {\n\t\t\treturn false, fmt.Sprintf(\"store fill %d returned false\", i)\n\t\t}\n\t\tfilled++\n\t}\n\tif len(attacker) != 64 {\n\t\treturn false, fmt.Sprintf(\"attacker buffer=%d, want 64\", len(attacker))\n\t}\n\t// Drain the honest listener so it has room; attacker stays full.\n\tdrained := 0\n\tfor len(honest) > 0 {\n\t\t<-honest\n\t\tdrained++\n\t}\n\n\tprobe := &chat.Envelope{ID: \"probe-honest-must-see\", From: \"aa\", To: \"bb\", Message: \"hello\"}\n\tif !s.Store(probe) {\n\t\treturn false, \"probe store returned false\"\n\t}\n\n\tattackerGotProbe := false\n\t// Attacker is full: the send hit default, so the probe must not be sitting\n\t// as a 65th item (cap 64) and must not be readable without dropping fills.\n\tattackerLenAfter := len(attacker)\n\tselect {\n\tcase env := <-honest:\n\t\tif env.ID != probe.ID {\n\t\t\treturn false, \"honest received unexpected id \" + env.ID\n\t\t}\n\tdefault:\n\t\treturn false, \"honest listener did not receive the probe\"\n\t}\n\n\t// Confirm attacker did not take the probe (still 64 fill envelopes).\n\tselect {\n\tcase env := <-attacker:\n\t\tif env.ID == probe.ID {\n\t\t\tattackerGotProbe = true\n\t\t}\n\tdefault:\n\t}\n\n\tdetail := fmt.Sprintf(\n\t\t\"Subscribe buffer cap=64 filled=%d drained_honest=%d\\n\"+\n\t\t\t\"after probe: attacker_len=%d attacker_got_probe=%v honest_got_probe=%v\",\n\t\tfilled, drained, attackerLenAfter, attackerGotProbe, true,\n\t)\n\tok := attackerLenAfter == 64 && !attackerGotProbe\n\treturn ok, detail\n}\n```\n\n**Run** (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):\n\n```\n=== RUN   TestPoC_F13\nPASS: F13 overflow drop is per-listener; honest subscriber still receives\nSubscribe buffer cap=64 filled=64 drained_honest=64\nafter probe: attacker_len=64 attacker_got_probe=false honest_got_probe=true\n--- PASS: TestPoC_F13 (0.00s)\nPASS\nok  \tgithub.com/xeprotocol/xe-poc/f13\t0.009s\n```\n\n## Fix suggestion\nCap concurrent SSE subscriptions per account or per IP, and exempt hijacked/streaming responses from the write timeout so legitimate streams are not reaped.","patch_refs":[{"id":158,"repo":"xeprotocol/xe","kind":"pr","ref":"139","title":"fix(api): cap concurrent chat SSE streams per IP and exempt streaming responses from write timeout (#50)","url":"https://github.com/xeprotocol/xe/pull/139","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1555,"source":"github","source_ref":"6755087546","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0027.","created_at":"2026-11-10T00:15:25+00:00"}]}