Report
XE Bounty — Laporan siap file (temuan pass 4 #2)
File issue baru di: https://github.com/xeprotocol/xe/issues/new Paste judul + isi di bawah. Akun GitHub: Gib230223.
Judul
[Low] Inbound connection cap is a check-then-act on a counter that only moves after the handshake (TOCTOU)
Isi
Summary
NetworkGater.InterceptSecured enforces the inbound connection cap by checking g.inbound.Load() >= max, but inbound is only incremented in the ConnectedF notify callback, which fires after the handshake completes. Nothing accounts for in-flight handshakes. A burst of concurrent inbound dials all observes inbound == 0 and all passes — 50/50 concurrent dials passed a cap of 2 in the PoC below, and even sequential checks pass, because nothing increments the counter without a ConnectedF event.
Evidence
// net/netcheck.go:40 — the cap:
defaultMaxInboundConns = 256
// net/netcheck.go:306-320 — InterceptSecured, the gate: checks the counter, never reserves:
func (g *NetworkGater) InterceptSecured(dir network.Direction, p peer.ID, _ network.ConnMultiaddrs) bool {
if g.isBanned(p) { return false }
if dir == network.DirInbound && !g.isTrusted(p) {
max := atomic.LoadInt64(&g.maxInbound)
if max > 0 && g.inbound.Load() >= max {
g.inboundRefused.Add(1)
return false
}
}
return true
}
// net/netcheck.go:340, :346 — the counter only moves in the notify callbacks, after the handshake:
ConnectedF: func(_ network.Network, conn network.Conn) {
if conn.Stat().Direction == network.DirInbound {
gater.inbound.Add(1) // :340 — after the handshake completes
}
...
},
DisconnectedF: func(_ network.Network, conn network.Conn) {
if conn.Stat().Direction == network.DirInbound {
if gater.inbound.Add(-1) < 0 { gater.inbound.Store(0) }
}
},
No other site touches the counter. Between the check and the increment there is no accounting for in-flight handshakes at all.
Impact (Low)
The overshoot is bounded by the libp2p connmgr (net/host.go:34: NewConnManager(100, 400, ...), 100 low / 400 high watermark) and the resource manager, so this is cap softening, not an unbounded bypass. A burst of inbound handshakes can still push the node well past its configured 256 inbound cap before any of them is counted. Fix: a reservation counter (increment in InterceptSecured, decrement on disconnect/failure) or counting in-flight handshakes.
Reproduction (PoC)
TestPoc4InboundCapToctou (package net, -race):
sequential InterceptSecured with maxInbound=2: allowed 10/10 (inbound counter still 0)
concurrent InterceptSecured with maxInbound=2: allowed 50/50
BUG REPRODUCED: 50 concurrent inbound handshakes passed a maxInbound=2 cap
Novelty note
No ticket covers the cap check. Board greps for inbound, InterceptSecured, maxInbound, connmgr return only XE-6670 (inbound handler re-arms sync), XE-5481 (revote backoff), XE-6445/XE-6559 (netcheck genesis checks), XE-0125 (discovery peerCount() counts inbound peers) — none is the cap check. GitHub search_issues for the cap keywords returns 0 results. Adjacency: GitHub #301 mentions the 256 cap only for sequential connect/disconnect churn (cap working as designed); this is simultaneous overshoot — different mechanism. Checked the live bounty board (High+Medium and Minor views) and the GitHub repo issues, 2026-11-12.
Repo: github.com/xeprotocol/xe, HEAD 89a542e, testnet-0005.
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-13352 and says what differs; it is read like any other.