[Low] Chat auth replay cache does a full O(N) sweep under a global lock on every verification
Report
Summary
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.
Root cause
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.
Verification
Measured with an in-package test (temporary, removed after the run; repo left clean):
- Sweep with empty map: 341ns
- Sweep with 24k entries: ~1.01ms
- Sweep with 100k entries: ~1.10ms
An 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.
Note on related reports
Searched 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.
Suggested fix
Evict lazily (e.g. only when the map exceeds a size threshold, or on a periodic timer outside the verification path), or shard the lock.
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-16853 and says what differs; it is read like any other.