Embedded TURN relays to the node's own public IP and to any internet host by default (and over TCP when TLS is on)
Describe the bug
With the embedded TURN server enabled and the default config, any room participant can use it as a general relay. The permission handler in pkg/service/turn.go (v1.13.7, lines 134–163) refuses loopback, private, link-local, multicast and unspecified peer addresses, and allows every other address. That includes:
- the node's own public IP, on any port (TURN permissions are per IP, not per port, RFC 5766), so a participant can reach other services on the host, such as SSH or a UDP service on 443;
- any public internet host (for example, a DNS query to 8.8.8.8:53 returns an answer);
- 100.64.0.0/10 (carrier-grade NAT), which
net.IP.IsPrivate()does not cover.
When turn.tls_port is set, pion/turn v5 also accepts RFC 6062 TCP allocations, so the same participant can open TCP connections to any allowed address and port. For example, connecting through the relay to the node's own port 22 returns the SSH banner.
TURN credentials come with every join, so this is open to anyone who can join a room. From reading the code (not tested), an existing allocation can still be refreshed after its credential expires.
As far as we can tell, the embedded TURN only ever needs to reach the node's own media ports (the ICE UDP port or range, and the ICE-TCP port).
Server
- Version: 1.13.7 (pion/turn v5.0.13)
- Environment: single node, Docker with host networking, embedded TURN on (UDP 3478, TLS behind an SNI proxy on 443)
Client
- SDK: none; a pion/turn v5 client using credentials derived the way the server does
- Version: n/a
To Reproduce
- Run livekit-server 1.13.7 with
turn.enabled: true,turn.udp_port: 3478andturn.tls_portset, with nodeny_peer_cidrs. - Join a room to get TURN credentials.
- Allocate a UDP relay, then CreatePermission for the node's public IP, send to port 443 and read the reply. Do the same for 8.8.8.8:53 with a DNS query.
- Over TURN/TLS, AllocateTCP, then Connect to the node's public IP on port 22.
- Steps 3 and 4 succeed.
Expected behavior By default, the embedded TURN relays only to the node's own media ports, or at least only to IPs the node owns. Relaying to arbitrary internet hosts, or to other ports on the node, should be opt-in.
Workaround
turn.deny_peer_cidrsset to every IPv4 range except the node's IP, plus::/0. This closes the relay to other hosts; the per-port gap on the node's own IP stays.- A host firewall rule on the relay port range that allows traffic to the node's IP only to the media ports, and rejects the rest.
Suggestions
- An option, or a default, that limits relay peers to the node's own IP(s) and media ports.
- A setting to turn off RFC 6062 TCP allocations when TURN/TLS is on (pion/turn v5 accepts them).
- Denying 100.64.0.0/10 along with the other restricted ranges.
- A note in the TURN docs and the sample config about
deny_peer_cidrs.
Source: livekit/livekit