Summary
Coturn suffers from a server-side request forgery issue where IPv4-mapped IPv6 loopback addresses bypass the default localhost protection in TURN relay handling.
Under certain configurations, an authenticated TURN client can cause the relay to access services bound only to 127.0.0.1 on the Coturn host, exposing internal interfaces that were expected to remain unreachable.
Affected context
This vulnerability arises in Coturn TURN/STUN server deployments where:
- The server is configured with default loopback peer rejection (without explicitly hardened custom policies)
- TURN relay traffic is allowed for authenticated clients
- Services on the Coturn host listen only on localhost (127.0.0.1 / ::1) and are assumed to be inaccessible externally
In this context, the TURN server can inadvertently act as a proxy, allowing authenticated clients to reach localhost-bound services using specially crafted peer addresses.
Exploit preconditions
- Attack surface: TURN relay functionality exposed by a Coturn server
- Required access: Valid TURN client credentials to allocate and use relay endpoints
- Trigger point: Submission of a TURN request containing a XOR-PEER-ADDRESS attribute with an IPv4-mapped IPv6 loopback address (e.g.,
::ffff:127.0.0.1) - Why exploitation is possible: The loopback detection logic (
ioa_addr_is_loopback) checks for the pure IPv6 loopback pattern before handling IPv4-mapped IPv6 addresses, meaning the default loopback guard does not treat these mapped addresses as localhost and does not reject them.
Why this happens
The core issue is an incomplete and order-dependent validation of peer addresses in the TURN server's loopback protection logic.
Coturn's ioa_addr_is_loopback routine focuses on recognizing the canonical IPv6 loopback form but fails to consistently classify IPv4-mapped IPv6 loopback addresses as localhost before policy decisions are made.
As a result, good_peer_addr does not apply the intended default rejection for loopback peers when they are represented in the mapped format, allowing authenticated clients to direct TURN relay traffic to 127.0.0.1 via ::ffff:127.0.0.1.
This pattern matches CWE-918: Server-Side Request Forgery (SSRF), where a server component unwittingly makes network requests to internal targets on behalf of a client due to insufficient target validation.
Potential impact
- Authenticated clients can access services bound only to localhost on the Coturn host
- Internal administrative APIs or debug endpoints may be exposed via TURN relay traffic
- Attackers could interact with local databases or message brokers listening on 127.0.0.1
- Sensitive configuration or status information may be retrieved from local management interfaces
- Further compromise may occur if internal services trust localhost-originated connections
General mitigation guidance
Effective mitigation focuses on strengthening address validation and reducing implicit trust in localhost and internal network targets.
Common defensive patterns include:
- Normalizing all incoming peer addresses to a canonical form before applying loopback and internal network checks
- Treating both IPv4 and IPv6 loopback representations, including IPv4-mapped IPv6, as equally sensitive and subject to strict rejection by default
- Implementing explicit allowlists for relay targets rather than relying on implicit assumptions about safety of particular address ranges
- Segregating the TURN server from internal services so that even if relay traffic is misdirected, sensitive endpoints are not reachable
- Ensuring local services do not automatically trust traffic simply because it appears to originate from localhost or the host's own network stack
How teams detect issues like this
Detection generally involves a mix of configuration review, code analysis, and traffic monitoring:
- Static analysis and code review: Look for address validation routines that treat IPv4, IPv6, and IPv4-mapped IPv6 differently or apply checks in an order that leaves edge cases unprotected. Pay special attention to logic around loopback and private network ranges.
- Configuration auditing: Review TURN server settings that govern peer address policies and relay constraints to confirm that loopback and internal segments are explicitly guarded.
- Network monitoring: Use logging and intrusion detection systems to identify TURN traffic targeting localhost or unusual internal addresses, especially via XOR-PEER-ADDRESS attributes.
- Policy enforcement: Introduce automated checks in deployment pipelines to flag configurations where the relay can reach host-local or otherwise sensitive interfaces, and to enforce standardized validation patterns for address handling.

