Chat Memory Leak & Unbounded State Exhaustion: ChatStore.messages lacks global capacity limit and account eviction
Report
Vulnerability Summary
In chat/chat.go:12-83, ChatStore manages in-memory chat messaging between accounts on the network:
type ChatStore struct {
mu sync.RWMutex
messages map[string][]*Envelope
seen map[string]int64
maxPerAccount int
listeners []chan *Envelope
listenerMu sync.Mutex
}
func (s *ChatStore) Store(env *Envelope) bool {
...
s.seen[env.ID] = env.Timestamp
s.storeFor(env.To, env)
if env.From != env.To {
s.storeFor(env.From, env)
}
s.mu.Unlock()
...
}
func (s *ChatStore) storeFor(account string, env *Envelope) {
msgs := s.messages[account]
if len(msgs) >= s.maxPerAccount {
newMsgs := make([]*Envelope, s.maxPerAccount)
copy(newMsgs, msgs[1:])
newMsgs[s.maxPerAccount-1] = env
s.messages[account] = newMsgs
} else {
s.messages[account] = append(msgs, env)
}
}
While s.seen implements time-based pruning (pruneSeenLocked), s.messages has no global bounds:
maxPerAccountonly caps the message slice length for a single account.- The number of keys in
s.messagesis completely unbounded. - No eviction or pruning mechanism exists anywhere in the codebase for
s.messages. Once an account is added tos.messages, it remains in memory permanently.
Any 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).
Root Cause Analysis
- Unbounded Map Dimension:
s.messagestracks accounts indefinitely with no TTL, LRU eviction, or maximum account limit. - Asymmetrical Pruning: Only
s.seenis cleaned up inpruneSeenLocked();s.messagesretains envelope pointers forever. - Unauthenticated Storage Amplification: In
node/node.go:2456-2469,account_chatp2p requests automatically store envelopes inChatStore.Store()without requiring an on-chain deposit or gas fee.
Proposed Remediation
- Implement an LRU or time-based eviction policy for inactive accounts in
ChatStore.messages. - Introduce a global memory or account cap (e.g.,
MaxTrackedAccounts = 10000). - Prune messages older than a configured retention window (e.g. 24 hours).
Thread
Thanks. This is the same finding as an earlier report that is not public, 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, file a new report that links https://bounty.xe.network/XE-10018 and says what differs; it is read like any other.