{"id":"XE-16867","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"677","source_url":"https://github.com/xeprotocol/xe/issues/677","reporter_id":2920,"title":"[Medium] SSH gateway per-IP limits have no IPv6 subnet grouping — one /64 fills all connection slots","area":"node-api","claimed_tier":"medium","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:51:55.804128+00:00","updated_at":"2026-11-22T23:26:11.354621+00:00","source_created_at":"2026-11-17T06:50:11+00:00","told_at":"2026-11-22T23:26:11.383577+00:00","status_changed_at":"2026-11-22T23:26:11.365844+00:00","url":"https://bounty.xe.network/XE-16867","body":"## Summary\n\nThe SSH gateway's per-IP pre-auth and session limits key on the **full remote IPv6 address** with no subnet grouping, so an attacker with a single IPv6 /64 (one standard allocation) can rotate source addresses and bypass the per-IP limits entirely, filling all gateway connection slots. The SSH gateway is the only limiter in the codebase without subnet grouping: the API rate limiter groups IPv6 by /64, and the libp2p resource manager groups by /56 *and* /48.\n\n## Root Cause\n\n`remoteIP` (`node/ssh_gateway.go:122-127`) returns the full remote host, and both limiters key on it verbatim:\n\n- `acquirePreAuth` (`node/ssh_gateway.go:130-142`): `maxPreAuthPerIP = 3` per address, `maxPreAuthConnections = 100` global (`:38-40`)\n- `promoteToSession` (`node/ssh_gateway.go:158-170`): `maxSessionsPerIP = 10` per address, `maxSSHConnections = 100` global (`:32-34`)\n\nContrast with the rest of the codebase:\n- `clientKey` (`api/handler.go:416-429`) groups IPv6 by /64 prefix.\n- `newResourceManager` (`net/host.go:90-99`) applies per-subnet limits at /56 *and* /48 for IPv6.\n\n## Impact\n\n**Pre-auth (no credentials needed):** 3 slots per rotated address → all 100 `maxPreAuthConnections` slots filled. Each held connection dies at the 10s handshake deadline (`sshHandshakeDeadline`, `node/ssh_gateway.go:36`), but sustained reconnects keep the gateway locked out indefinitely. Legitimate tenants cannot connect.\n\n**Sessions (one valid lease key):** 10 sessions per rotated address → all 100 `maxSSHConnections` slots filled, and with no post-auth idle timeout (`conn.SetDeadline(time.Time{})` after handshake, `node/ssh_gateway.go:240`) they stay filled indefinitely.\n\n## Verification\n\nExecuted in-package test against the real accounting functions (`acquirePreAuth` / `promoteToSession`):\n\n```\nsingle IPv6 address 2001:db8::1: 3 pre-auth allowed, 4th rejected\nrotating within 2001:db8::/64: 97 additional pre-auth slots acquired\npreAuthTotal now 100 (global cap maxPreAuthConnections=100)\nrotating within 2001:db8::/64: 100 authenticated sessions acquired (global cap maxSSHConnections=100)\n```\n\nContrast test confirms the API limiter puts the whole /64 in one bucket: `clientKey(2001:db8::1) = clientKey(2001:db8::2) = clientKey(2001:db8::ffff) = 2001:db8::/64`.\n\n## Note on related reports\n\nDistinct from #67 (awarded; pre-auth exhaustion with *no handshake deadline* on testnet-0005 — fixed on HEAD with the 10s deadline plus per-IP limits; this report is about the per-IP limits in that fix being bypassable via address rotation). Distinct from #643 (unbounded channels per connection) and #584 (lease never re-validated). Searched \"SSH gateway IPv6\", \"maxSessionsPerIP pre-auth limit\", \"IPv6 rotation rate limit /64\" — no covering report found.\n\n## Suggested fix\n\nGroup IPv6 remotes by /64 (or /56, matching the libp2p layer) in `remoteIP` / `acquirePreAuth` / `promoteToSession`, mirroring `clientKey` in `api/handler.go`.","patch_refs":[],"thread":[{"id":18792,"source":"desk","source_ref":"reply:16469","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-16867 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:11.354621+00:00"}]}