Bounty
XE-10018 · Bounty

Chat Memory Leak & Unbounded State Exhaustion: ChatStore.messages lacks global capacity limit and account eviction

Closed · duplicate — web filed 2026-11-12 09:15 UTC by xe:e4cd6974

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:

  1. maxPerAccount only caps the message slice length for a single account.
  2. The number of keys in s.messages is completely unbounded.
  3. 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.

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

  1. Unbounded Map Dimension: s.messages tracks accounts indefinitely with no TTL, LRU eviction, or maximum account limit.
  2. Asymmetrical Pruning: Only s.seen is cleaned up in pruneSeenLocked(); s.messages retains envelope pointers forever.
  3. 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.

Proposed Remediation

  1. Implement an LRU or time-based eviction policy for inactive accounts in ChatStore.messages.
  2. Introduce a global memory or account cap (e.g., MaxTrackedAccounts = 10000).
  3. Prune messages older than a configured retention window (e.g. 24 hours).

Thread

Joseph Denneteam2026-11-20 00:33 UTCdesk

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.