{"id":"XE-9181","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":2008,"title":"ChatStore `seen` cap fails closed: a sustained flood of valid envelopes rejects all new chat","area":"p2p-sync","claimed_tier":"medium","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-12T03:11:37.940794+00:00","updated_at":"2026-11-20T00:04:29.209734+00:00","source_created_at":null,"told_at":"2026-11-20T00:04:29.241567+00:00","status_changed_at":"2026-11-20T00:04:29.217873+00:00","url":"https://bounty.xe.network/XE-9181","body":"# ChatStore `seen` cap fails closed: a sustained flood of valid envelopes rejects all new chat\r\n\r\n**Suggested XE tier:** Medium (chat starvation only; Track 2 treats chat starvation as High when one client can cause it — this claim is narrower, because sustaining it at the default PoW difficulty needs substantial compute and several peers; see Limitations. Triage may raise or lower.)\r\n**Area:** P2P / sync (chat ingestion; also Node / API via `POST /chat/send`)\r\n**Severity:** CVSS 3.1 `AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H` — 5.9 Medium\r\n\r\nCVSS justification:\r\n\r\n- `AV:N` — envelopes arrive over the P2P `account_chat` handler (and via the HTTP API) from the network.\r\n- `AC:H` — sustaining the cap needs a continuous ~167 valid envelopes/second for as long as the denial lasts (see Impact), each carrying proof-of-work at the configured difficulty, delivered through enough peers/IPs to stay under per-peer and per-IP rate limits. At the default difficulty this is a substantial compute commitment; if `ChatDifficulty` is 0, PoW is skipped and the cost collapses (see Limitations).\r\n- `PR:N` — envelopes are self-signed with the sender's own keypair; no account, lease, or admin privilege is needed.\r\n- `UI:N` — no victim interaction.\r\n- `S:U` — impact stays within the target node's chat ingestion; the ledger, consensus, and other node functions are not claimed to be affected.\r\n- `C:N`, `I:N` — no confidentiality or integrity impact shown.\r\n- `A:H` — while the cap is held full, *all* new envelopes are rejected by `Store`, including legitimate ones, on the target node.\r\n\r\n**Asset:** `xeprotocol/xe`, `chat/chat.go` + `node/node.go` (`account_chat` handler), at commit `89a542ea51d38375299aee54c6c99102e9bfa666` (2026-11-10, testnet-0005)\r\n**Accounts:** none on any live network. Local harness / isolated private nodes only, with test keypairs generated locally.\r\n\r\n## Summary\r\n\r\n`ChatStore.Store` caps its `seen` map at 100,000 IDs and, when the cap is reached, only prunes entries older than 10 minutes before rejecting the new envelope. An attacker who keeps 100,000 fresh, valid envelope IDs in the map therefore makes `Store` return `false` for every new envelope, including legitimate ones, for as long as the flood is sustained. There is no LRU eviction and no exception for envelopes addressed to the local account.\r\n\r\n## Affected component\r\n\r\n- `xe/chat/chat.go:10` (`maxSeenIDs = 100_000`), `:30-42` (`Store`), `:63-70` (`pruneSeenLocked`)\r\n- Ingress: `xe/node/node.go:2456-2466` (`account_chat` handler — validated envelope, then `Store`, failure reported as \"duplicate envelope\"), `xe/node/node.go:2482-2506` (`SendChat`), `xe/api/chat.go` (`POST /chat/send` → `SendChat`)\r\n- Envelope validation: `xe/chat/envelope.go:17` (`DefaultPoWDifficulty`), `:19` (`MaxEnvelopeSkew = 5 minutes`), `:85-113` (`VerifyFull` — freshness window, ID recomputation, PoW, key/signature checks)\r\n- Rate limits that bound the flood: P2P Messenger 50 RPS/peer, 200 RPS global (`xe/net/msg.go:26-30`); HTTP write limit 10 RPS/IP, burst 50 (`xe/api/handler.go:297`)\r\n\r\n## Steps to reproduce (local only, isolated — do NOT run against the public testnet)\r\n\r\nThe reproduction is a local harness, not a live flood. It has **not** been executed yet. This report is based on static code review at the stated HEAD; the steps below describe the local reproduction that can confirm it.\r\n\r\n1. On an isolated machine/network with no connection to the public testnet, check out `xeprotocol/xe` at the commit above and install a Go toolchain (Go 1.25 per `.go-version`). No live node is involved.\r\n2. Write a small local Go harness that constructs a `chat.ChatStore` directly and calls `Store`:\r\n   - Generate one test keypair locally.\r\n   - Create 100,000 distinct valid envelopes with that keypair (distinct messages/timestamps, valid signatures; PoW is not exercised by `Store` itself — see step 4 for the full-path variant).\r\n   - Call `Store` for each; all should return `true` until the cap is reached.\r\n3. Create one further legitimate envelope (different test keypair, fresh timestamp) and call `Store`.\r\n   - Expected from the code (not yet observed): `Store` returns `false`, because `pruneSeenLocked` only removes entries older than 10 minutes and all 100,000 entries are fresh.\r\n4. Full-path variant (optional, still isolated): run two local nodes on a private libp2p network with no public peers, with `ChatDifficulty` set to a low test value so the harness can generate envelopes cheaply, flood node B's `account_chat` handler from node A, then send one legitimate envelope to B and observe the \"duplicate envelope\" error.\r\n\r\n## Evidence\r\n\r\nCode at HEAD (`xe/chat/chat.go`):\r\n\r\n```go\r\nconst maxSeenIDs = 100_000\r\n\r\nfunc (s *ChatStore) Store(env *Envelope) bool {\r\n\ts.mu.Lock()\r\n\tif _, dup := s.seen[env.ID]; dup { s.mu.Unlock(); return false }\r\n\tif len(s.seen) >= maxSeenIDs {\r\n\t\ts.pruneSeenLocked()\r\n\t\tif len(s.seen) >= maxSeenIDs { s.mu.Unlock(); return false }\r\n\t}\r\n\ts.seen[env.ID] = env.Timestamp\r\n\t...\r\n}\r\n\r\nfunc (s *ChatStore) pruneSeenLocked() {\r\n\tcutoff := core.Now().Add(-2 * MaxEnvelopeSkew).UnixNano() // 10 minutes\r\n\tfor id, ts := range s.seen { if ts < cutoff { delete(s.seen, id) } }\r\n}\r\n```\r\n\r\nIngress (`xe/node/node.go`, `account_chat` handler): a validated envelope that `Store` rejects is answered with `fmt.Errorf(\"duplicate envelope\")` — indistinguishable, from the sender's side, from a genuine duplicate.\r\n\r\nArithmetic (from the code, not from a live measurement): entries survive in `seen` for up to 10 minutes (2 × 5-minute skew). Holding 100,000 fresh entries therefore needs roughly 100,000 / 600 s ≈ 167 valid envelopes/second, sustained. That rate fits within the 200 RPS global Messenger limit if delivered through at least 4 peers at 50 RPS each, or through enough distinct HTTP IPs at 10 RPS/IP.\r\n\r\n## Impact\r\n\r\nWhile the flood is sustained, the target node's chat ingestion is fully denied: every new envelope — including legitimate messages to any account on that node — is rejected. The denial ends when the flood stops and entries age past the 10-minute prune cutoff; no persistent corruption is claimed. The ledger and consensus paths are not affected by this mechanism as far as this report shows.\r\n\r\n## Dedup / related reports\r\n\r\n- **Variant, not a duplicate of the closest reports** (as assessed from the 300-report desk snapshot of 2026-11-12 and targeted GitHub searches; dedup is provisional — see Limitations):\r\n  - GitHub `xeprotocol/xe#247`: the `messages` map grows without bound (memory/OOM). This report is about the *capped* `seen` map failing closed, not unbounded growth.\r\n  - XE-0001 finding 4: storage sink for arbitrary accounts. Different mechanism (per-account storage), different cap.\r\n  - XE-0610: per-account inbox eviction. Different map and different eviction behaviour.\r\n  - XE-3519: the `seen` map in chat-auth (`api/chat_auth.go`), a different map with a different claim (unbounded memory).\r\n- No entry in the 300-report snapshot mentions total rejection caused by the `seen` cap. If the team finds an earlier report of this exact fail-closed behaviour, this should be treated as a duplicate/variant of it.\r\n\r\n## Limitations — what was NOT verified\r\n\r\n- **Not executed.** No Go toolchain was available during preparation, so no harness, `go vet`, or `go test` was run. The `Store` behaviour above is read from the code; the local run is still outstanding.\r\n- **PoW cost at the default difficulty is substantial.** `ValidatePoW` requires `powHash >= 0xffffc00000000000`, i.e. success probability 2⁻¹⁸, about 262,144 hashes per envelope on average. Sustaining 167 envelopes/second at that difficulty needs on the order of 44M hashes/second plus the peer/IP distribution above. The claim is therefore *sustained flood by a well-resourced sender*, not a trivial single-request DoS. If `ChatDifficulty` is configured to 0, `VerifyFull` skips PoW entirely and the cost collapses — the deployed testnet value was not verified (no live testing).\r\n- **No live testing.** Whether the public testnet nodes run this HEAD, what `ChatDifficulty` they use, and how the flood interacts with peer scoring/banning in practice were not tested and are not claimed.\r\n- Dedup is provisional: private reports are not visible and GitHub issues were searched by targeted query, not enumerated in full.\r\n\r\n## Remediation\r\n\r\nEvict instead of failing closed, at the layer that owns the cap (`chat/chat.go`):\r\n\r\n1. Replace the fail-closed cap with bounded eviction: when `seen` is full, evict the oldest entries (LRU / oldest-timestamp) to make room, so a flood degrades replay protection for old envelopes instead of denying all new chat. Size the cap and eviction so the map stays bounded.\r\n2. Alternatively, prune more aggressively (for example, drop entries older than the 5-minute freshness window rather than 2× skew, since envelopes older than the skew window are rejected by `VerifyFull` anyway) — this narrows, but does not remove, the flood window, so it should be combined with eviction.\r\n3. Consider per-sender/per-peer accounting for `seen` growth so one keypair cannot fill the whole map, and return a distinct error for \"store full\" instead of \"duplicate envelope\" so operators can distinguish a flood from genuine duplicates.\r\n\r\n## Notes\r\n\r\n- Reviewed 2026-11-12 against a local clone at the commit above. No live testing, no testnet contact, no accounts on any live network.\r\n- Track 2 note: any future volume measurement against the public testnet would require a pre-notice report first under the program rules, and the reporter's explicit go-ahead. None was done for this report.","patch_refs":[],"thread":[{"id":12660,"source":"desk","source_ref":"reply:10682","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-9181 and says what differs; it is read like any other.","created_at":"2026-11-20T00:04:29.209734+00:00"}]}