{"id":"XE-10018","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":730,"title":"Chat Memory Leak & Unbounded State Exhaustion: ChatStore.messages lacks global capacity limit and account eviction","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-12T09:15:24.400553+00:00","updated_at":"2026-11-20T00:33:20.156906+00:00","source_created_at":null,"told_at":"2026-11-20T00:33:20.184879+00:00","status_changed_at":"2026-11-20T00:33:20.167549+00:00","url":"https://bounty.xe.network/XE-10018","body":"## Vulnerability Summary\n\nIn `chat/chat.go:12-83`, `ChatStore` manages in-memory chat messaging between accounts on the network:\n\n```go\ntype ChatStore struct {\n\tmu            sync.RWMutex\n\tmessages      map[string][]*Envelope\n\tseen          map[string]int64\n\tmaxPerAccount int\n\tlisteners     []chan *Envelope\n\tlistenerMu    sync.Mutex\n}\n\nfunc (s *ChatStore) Store(env *Envelope) bool {\n...\n\ts.seen[env.ID] = env.Timestamp\n\ts.storeFor(env.To, env)\n\tif env.From != env.To {\n\t\ts.storeFor(env.From, env)\n\t}\n\ts.mu.Unlock()\n...\n}\n\nfunc (s *ChatStore) storeFor(account string, env *Envelope) {\n\tmsgs := s.messages[account]\n\tif len(msgs) >= s.maxPerAccount {\n\t\tnewMsgs := make([]*Envelope, s.maxPerAccount)\n\t\tcopy(newMsgs, msgs[1:])\n\t\tnewMsgs[s.maxPerAccount-1] = env\n\t\ts.messages[account] = newMsgs\n\t} else {\n\t\ts.messages[account] = append(msgs, env)\n\t}\n}\n```\n\nWhile `s.seen` implements time-based pruning (`pruneSeenLocked`), `s.messages` has no global bounds:\n1. `maxPerAccount` only caps the message slice length for a single account.\n2. The number of keys in `s.messages` is completely unbounded.\n3. No eviction or pruning mechanism exists anywhere in the codebase for `s.messages`. Once an account is added to `s.messages`, it remains in memory permanently.\n\nAny network participant or API caller can generate random ephemeral recipient accounts (`env.To`). Every chat message creates new map entries in `s.messages`. An attacker sending chat messages across millions of distinct destination addresses inflates `s.messages` without constraint, consuming gigabytes of heap memory until the node process crashes due to out-of-memory (OOM).\n\n## Root Cause Analysis\n\n1. Unbounded Map Dimension: `s.messages` tracks accounts indefinitely with no TTL, LRU eviction, or maximum account limit.\n2. Asymmetrical Pruning: Only `s.seen` is cleaned up in `pruneSeenLocked()`; `s.messages` retains envelope pointers forever.\n3. Unauthenticated Storage Amplification: In `node/node.go:2456-2469`, `account_chat` p2p requests automatically store envelopes in `ChatStore.Store()` without requiring an on-chain deposit or gas fee.\n\n## Proposed Remediation\n\n1. Implement an LRU or time-based eviction policy for inactive accounts in `ChatStore.messages`.\n2. Introduce a global memory or account cap (e.g., `MaxTrackedAccounts = 10000`).\n3. Prune messages older than a configured retention window (e.g. 24 hours).","patch_refs":[],"thread":[{"id":13245,"source":"desk","source_ref":"reply:11267","author":"Joseph Denne","team":true,"body":"Thanks. This is the same finding as an earlier report that is not public, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-10018 and says what differs; it is read like any other.","created_at":"2026-11-20T00:33:20.156906+00:00"}]}