{"id":"XE-16690","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"643","source_url":"https://github.com/xeprotocol/xe/issues/643","reporter_id":2920,"title":"[High] SSH gateway: unbounded channels per authenticated connection exhaust gateway goroutines and flood VM sshd","area":"node-api","claimed_tier":"high","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-17T05:13:22.767947+00:00","updated_at":"2026-11-22T23:26:17.501037+00:00","source_created_at":"2026-11-17T05:12:42+00:00","told_at":"2026-11-22T23:26:17.564503+00:00","status_changed_at":"2026-11-22T23:26:17.515124+00:00","url":"https://bounty.xe.network/XE-16690","body":"## Summary\nThe SSH gateway (`node/ssh_gateway.go`) limits TCP connections (100 total, 10 per IP) but places no limit on SSH channels per connection. After authenticating once with a valid lease, a client can open an unbounded number of `session` and `direct-tcpip` channels. Each `direct-tcpip` channel opens a libp2p tunnel to the provider VM's sshd plus two `io.Copy` goroutines; each `session` channel spawns a goroutine. One cheap lease can therefore exhaust the gateway's goroutines/memory and trip the VM sshd's `MaxStartups`, denying SSH to the legitimate consumer and other tenants.\n\n## Root Cause\n- `promoteToSession` (`node/ssh_gateway.go:177-190`) is called once per TCP connection after `ssh.NewServerConn` and enforces only the connection-level caps.\n- The channel loop (`node/ssh_gateway.go:218-245`) accepts every `session` and `direct-tcpip` channel with no per-connection, per-lease, or global channel counter:\n  - `session` -> `go gw.handleSession(...)`\n  - `direct-tcpip` -> `go gw.handleDirectTCPIP(...)` -> `OpenTunnel` (libp2p stream + 2 goroutines + handler + watcher)\n- `golang.org/x/crypto/ssh` (`mux.go:handleChannelOpen`) imposes no channel-count limit; it forwards every open to the application.\n\n## Impact\n- Gateway-wide DoS: tens of thousands of channels from one authenticated connection = unbounded goroutine and memory growth on the gateway node.\n- Cross-tenant DoS: unbounded `direct-tcpip` channels open an unbounded number of concurrent TCP connections to the provider VM's sshd, tripping `MaxStartups` and denying SSH to the legitimate lease consumer and other tenants on that VM.\n- The 100/10 connection limits do not bound this at all.\n\n## Verification\nSource-level: the limits in `ssh_gateway.go` (`maxSSHConnections`, `maxSessionsPerIP`) are only consulted in `promoteToSession`, which runs once per connection; the `for newChan := range chans` loop has no counter or cap. Audited at HEAD `8cc209d` (testnet-0006).\n\n## Suggested fix\nCap channels per connection (e.g. 16-32) and per lease; reject excess channel opens.","patch_refs":[],"thread":[{"id":18886,"source":"desk","source_ref":"reply:16563","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-16690 and says what differs; it is read like any other.","created_at":"2026-11-22T23:26:17.501037+00:00"}]}