Skip to content

Embedded TURN relays to the node's own public IP and to any internet host by default (and over TCP when TLS is on) #4924

Closed

Description

@alvorado-lab

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

  1. Run livekit-server 1.13.7 with turn.enabled: true, turn.udp_port: 3478 and turn.tls_port set, with no deny_peer_cidrs.
  2. Join a room to get TURN credentials.
  3. 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.
  4. Over TURN/TLS, AllocateTCP, then Connect to the node's public IP on port 22.
  5. 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_cidrs set 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

  1. An option, or a default, that limits relay peers to the node's own IP(s) and media ports.
  2. A setting to turn off RFC 6062 TCP allocations when TURN/TLS is on (pion/turn v5 accepts them).
  3. Denying 100.64.0.0/10 along with the other restricted ranges.
  4. A note in the TURN docs and the sample config about deny_peer_cidrs.

Activity

  1. dennis-xd commented on Oct 6, 2026

    @dennis-xd

    Hi @boks1971 , i've been looking with this and happy to put up a PR. Before i do, there're a few design points i'd like your input on

    My approach would be: Embedded TURN may relay only to a known Livekit endpoint (IP + configured RTC media port). Default declined for everything else.

    Proposal

    1. For UDP Allocation, Pion's PermissionHandler only works with IP so no port distinguish, I suggest wrap net.PacketConn so wraps around for port supported.
    2. For RFC 6062 TCP Allocation, considering disable it.
    3. Adding carrier-grade NAT 100.64.0.0/10 to restricted ranges. allow_restricted_peer_cidrs could override this.
    4. Most important one: Cluster endpoint discovery: livekit.Node.Ip right now only has NodeIP.PrimaryIP(), I propose having the RTC configuration code expose its effective media endpoints and publishing them in the node registry advertised IP + protocol + port/range. TURN instances would periodically compile the registered endpoints into an immutable in-memory allow-list. Redis would not be accessed from the packet path.
    5. If breaking changes are not welcome, can add a media-only policy value default to false.
  2. cnderrauber commented on Oct 9, 2026

    @cnderrauber
    Contributor

    @dennis-xd Thank you for looking at this! Your proposal looks good to me, except we don't want to use the registry to advertise the allow list (media entry points). I'll take this issue

  3. self-assigned this
    on Oct 9, 2026
  4. cnderrauber commented on Oct 13, 2026

    @cnderrauber
    Contributor

    close by #4992

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions