<!-- XE-16690 · [High] SSH gateway: unbounded channels per authenticated connection exhaust gateway goroutines and flood VM sshd · testnet -->
*Markdown view of <https://bounty.xe.network/XE-16690>. The page is the record; this is the same page for reading.*

XE-16690 · Bounty

# \[High\] SSH gateway: unbounded channels per authenticated connection exhaust gateway goroutines and flood VM sshd

Closed · duplicate
—claimed High
[xe#643](https://github.com/xeprotocol/xe/issues/643)
filed 2026-11-17 05:12 UTC
by kecedanzz77-bit

Verdict
:   Duplicate

Tier
:   —

Claimed
:   High

Area
:   Node / API

Duplicate of
:   —

Tracked
:   —

Updated
:   2026-11-22 23:26 UTC

Told
:   2026-11-22 23:26 UTC

### Patches

None linked.

### History

- [770292](https://bounty.xe.network/log/770292) 2026-11-22 23:27 UTC reply.mirror\_failed
- [770131](https://bounty.xe.network/log/770131) 2026-11-22 23:26 UTC proposal.adopted
- [770130](https://bounty.xe.network/log/770130) 2026-11-22 23:26 UTC reply.sent
- [770129](https://bounty.xe.network/log/770129) 2026-11-22 23:26 UTC proposal.adopted
- [770128](https://bounty.xe.network/log/770128) 2026-11-22 23:26 UTC ticket.status new → closed
- [769390](https://bounty.xe.network/log/769390) 2026-11-22 23:26 UTC proposal.adopted
- [769389](https://bounty.xe.network/log/769389) 2026-11-22 23:26 UTC ticket.facts area
- [769388](https://bounty.xe.network/log/769388) 2026-11-22 23:26 UTC proposal.adopted
- [769387](https://bounty.xe.network/log/769387) 2026-11-22 23:26 UTC ticket.facts
- [769386](https://bounty.xe.network/log/769386) 2026-11-22 23:26 UTC proposal.adopted
- [769385](https://bounty.xe.network/log/769385) 2026-11-22 23:26 UTC ticket.facts
- [766040](https://bounty.xe.network/log/766040) 2026-11-22 23:17 UTC note.added

[Full history](https://bounty.xe.network/log?ref=XE-16690) · [JSON](https://bounty.xe.network/v1/tickets/XE-16690) · [markdown](https://bounty.xe.network/XE-16690.md)

### Report

## Summary

The 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.

## Root Cause

- `promoteToSession` (`node/ssh_gateway.go:177-190`) is called once per TCP connection after `ssh.NewServerConn` and enforces only the connection-level caps.
- 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:
  - `session` -\> `go gw.handleSession(...)`
  - `direct-tcpip` -\> `go gw.handleDirectTCPIP(...)` -\> `OpenTunnel` (libp2p stream \+ 2 goroutines \+ handler \+ watcher)
- `golang.org/x/crypto/ssh` (`mux.go:handleChannelOpen`) imposes no channel-count limit; it forwards every open to the application.

## Impact

- Gateway-wide DoS: tens of thousands of channels from one authenticated connection \= unbounded goroutine and memory growth on the gateway node.
- 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.
- The 100/10 connection limits do not bound this at all.

## Verification

Source-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).

## Suggested fix

Cap channels per connection (e.g. 16-32) and per lease; reject excess channel opens.

### Thread

**Joseph Denne**team2026-11-22 23:26 UTCdesk

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-16690 and says what differs; it is read like any other.
