{"id":"XE-16853","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"676","source_url":"https://github.com/xeprotocol/xe/issues/676","reporter_id":2920,"title":"[Low] Chat auth replay cache does a full O(N) sweep under a global lock on every verification","area":"node-api","claimed_tier":null,"assessed_tier":null,"verdict":"duplicate","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-17T06:41:34.342985+00:00","updated_at":"2026-11-22T23:26:11.462809+00:00","source_created_at":"2026-11-17T06:39:40+00:00","told_at":"2026-11-22T23:26:11.507686+00:00","status_changed_at":"2026-11-22T23:26:11.472475+00:00","url":"https://bounty.xe.network/XE-16853","body":"## Summary\n\n`chatAuthState.verifyProof` iterates the entire `seen` map to evict expired entries on every call, holding the global mutex for the whole scan. Entries are added on each successful verification, so an attacker with a throwaway keypair can grow the map and make every chat-auth verification on the node pay a linear scan under a shared lock.\n\n## Root cause\n\n`api/chat_auth.go` `verifyProof` (`:73-112`): after the signature checks, it takes `s.mu.Lock()` and runs `for k, exp := range s.seen { if now > exp { delete(s.seen, k) } }` before checking/inserting the nonce. The sweep runs on every verification, under a lock shared by all chat-auth verifications.\n\n## Verification\n\nMeasured with an in-package test (temporary, removed after the run; repo left clean):\n- Sweep with empty map: **341ns**\n- Sweep with 24k entries: **~1.01ms**\n- Sweep with 100k entries: **~1.10ms**\n\nAn attacker adds ~200 entries/s per IP (read rate limit), TTL 120s → ~24k steady-state entries per IP, and IPv6 /64 rotation multiplies it (the rate limiter groups by /64). Honest bounds: single-IP steady state (~24k entries) is roughly a ~1ms mutex hold per verification plus serialization of all chat-auth verifications; multi-/64 growth is what makes it serious.\n\n## Note on related reports\n\nSearched `chat challenge replay seen map` — 0 hits. Note: the same O(N)-sweep pattern exists in `node/attestation.go` `allowAttestation`, but that map only grows on *successful* attestations (live leases only), so it is not separately claimed.\n\n## Suggested fix\n\nEvict lazily (e.g. only when the map exceeds a size threshold, or on a periodic timer outside the verification path), or shard the lock.","patch_refs":[],"thread":[{"id":18794,"source":"desk","source_ref":"reply:16471","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-16853 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:11.462809+00:00"}]}