<!-- XE-10018 · Chat Memory Leak & Unbounded State Exhaustion: ChatStore.messages lacks global capacity limit and account eviction · testnet -->
*Markdown view of <https://bounty.xe.network/XE-10018>. The page is the record; this is the same page for reading.*

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   —

Area
:   P2P / sync

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-20 00:33 UTC

Told
:   2026-11-20 00:33 UTC

### Patches

None linked.

### History

- [552609](https://bounty.xe.network/log/552609) 2026-11-20 00:33 UTC proposal.adopted
- [552608](https://bounty.xe.network/log/552608) 2026-11-20 00:33 UTC reply.sent
- [552607](https://bounty.xe.network/log/552607) 2026-11-20 00:33 UTC ticket.status new → closed
- [552030](https://bounty.xe.network/log/552030) 2026-11-20 00:33 UTC proposal.adopted
- [552029](https://bounty.xe.network/log/552029) 2026-11-20 00:33 UTC ticket.facts area
- [552028](https://bounty.xe.network/log/552028) 2026-11-20 00:33 UTC proposal.adopted
- [552027](https://bounty.xe.network/log/552027) 2026-11-20 00:33 UTC ticket.facts
- [552026](https://bounty.xe.network/log/552026) 2026-11-20 00:33 UTC proposal.adopted
- [552025](https://bounty.xe.network/log/552025) 2026-11-20 00:33 UTC ticket.facts
- [550924](https://bounty.xe.network/log/550924) 2026-11-20 00:31 UTC note.added
- [550923](https://bounty.xe.network/log/550923) 2026-11-20 00:31 UTC proposal.created
- [550922](https://bounty.xe.network/log/550922) 2026-11-20 00:31 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-10018) · [JSON](https://bounty.xe.network/v1/tickets/XE-10018) · [markdown](https://bounty.xe.network/XE-10018.md)

### 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 Denne**team2026-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.
