1
0
mirror of https://github.com/coturn/coturn.git synced 2026-04-03 03:10:59 +02:00

1869 Commits

Author SHA1 Message Date
Carlos Ruiz Ballesteros
a4756d482f
fix: restore RFC 3489 (old STUN) backward compatibility broken since 4.7.0 (#1839)
## Problem

Since 4.7.0, `--stun-backward-compatibility` no longer works. Legacy
STUN clients (RFC 3489, pre-magic-cookie) receive no response even when
the option is explicitly enabled.

## Root Cause

Commit 4cc076d renamed `no_stun_backward_compatibility` (negative logic)
to `stun_backward_compatibility` (positive logic). Two call sites were
not updated correctly:

1. **`src/server/ns_turn_server.c`**: the
`old_stun_is_command_message_str` branch in the TCP/stream socket
handler kept `!` on the renamed variable, inverting the condition. Old
STUN was processed only when backward compat was *off*.

2. **`src/apps/relay/dtls_listener.c`**: the UDP/DTLS early packet
validation block never included an `old_stun_is_command_message_str`
check, so old STUN packets were always classified as invalid regardless
of the backward compat flag.

## Fix

- **`ns_turn_server.c`**: Remove the stray `!` negation restoring
correct condition semantics.
- **`dtls_listener.c`**: Add the missing old-STUN branch in the UDP
packet validation block, guarded by
`turn_params.stun_backward_compatibility`.
2026-03-25 23:16:21 -07:00
tyranron
ba571ad795
Update Debian "trixie" to 20260316 snapshot in Docker image 2026-03-17 13:43:57 +02:00
redraincatching
86e5e72718
Change port identifiers to use uint16_t (#1752)
based on the ideas originally developed in [this
pr](https://github.com/coturn/coturn/pull/1535) by @WHYHD

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2026-03-14 19:47:15 -07:00
Pavel Punsky
85ff6cd2fb
Create CLAUDE.md file (#1835)
Create a file that can be used with Claude and add some high level
definitions
2026-03-14 18:25:54 -07:00
Pavel Punsky
75f8133c40
Fixes: run_tests.sh and no db (#1834) 2026-03-12 22:01:28 -07:00
Captain Picarl
a6028ddd8a
Improve PostgreSQL.md Clarity (#1833)
A rewrite and reformat of the PostgreSQL.md file:
- Applies some minor formatting to the document. 
- Applies consistency between the 'turn' user and 'coturn' database
names.
- Adds some warnings about issues I encountered during my own
installation process (public schema error)
- Adds a minor example of restarting a service with SystemD
2026-03-12 20:53:40 -07:00
mesibo
65c4445227
Add session usage reporting callback to TURN database driver (#1794)
We use Coturn in production at [mesibo](https://mesibo.com) and
identified a gap in dbdriver: there's no callback to capture
post-session metrics like duration, bandwidth consumed, timestamps, etc.

We've made the following changes, which could be useful for Coturn.
Would appreciate your consideration. These changes are tested in
production environments at mesibo.

## Changes for reporting usage

Added a `report_usage` callback to the database driver interface,
invoked at session termination. This allows drivers to capture and
persist detailed usage statistics in their preferred storage (MySQL,
PostgreSQL, etc.).

### 1. Database Driver Interface
**File:** `src/apps/relay/dbdrivers/dbdriver.h`

```c
typedef struct _turn_dbdriver_t {
    // ... existing callbacks
    void (*report_usage)(void *);
} turn_dbdriver_t;
```

### 2. Session Termination Hook
**File:** `src/apps/relay/ns_ioalib_engine_impl.c`

```c
void turn_report_session_usage(void *session, int force_invalid) {
    // ... existing code
    
    if(force_invalid) {
        const turn_dbdriver_t * dbd = get_dbdriver();
        if(dbd->report_usage)
            dbd->report_usage(session);
    }

   // ... existing code
   ss->received_packets = 0;
   ...
}
```

---------

Co-authored-by: Pavel Punsky <eakraly@users.noreply.github.com>
2026-03-08 19:48:54 -07:00
Pavel Punsky
44d201a4f9
Initialize variables before use (#1832) 2026-03-08 16:24:32 -07:00
Pavel Punsky
dbfa9dbb53
Replace perror with logging (#1831)
Replace all calls to `perror` with log message

perror printed messages do not follow logging format, sometimes provided
duplicate information
2026-03-08 16:24:00 -07:00
Pavel Punsky
9467af5041
CLI interface is disabled by default (#1830)
cli interface is ON by default which creates a security risk (even
though requires a password) and recommended to be disabled.
Instead of just recommendation, this PR disables CLI by default and now
requires an explicit flag to enable it

If using old configuration or cli arguments to turnserver - it will log
an error message about `--no-cli` being deprecated while doing nothing
(already disabled). This log line will be removed in the future
2026-03-06 18:00:45 -08:00
Pavel Punsky
20d8e38297
Disable reason string in response messages to reduce amplification factor (#1829)
Disable the messages by default - they can be re-enabled using
`--include-reason-string` option

As a result of not sending reason string (which is optional by standard
and provide debugging information for the actual numeric error code)
response message size can be decreased by up to NNN bytes.
2026-03-06 17:59:21 -08:00
dependabot[bot]
d6e828c717
Upgrade docker/setup-buildx-action from 3 to 4 version (#1828)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-06 00:26:51 +01:00
dependabot[bot]
679f9b4865
Upgrade docker/login-action from 3 to 4 version (#1826)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-05 12:38:23 +01:00
dependabot[bot]
8479d13b12
Upgrade docker/setup-qemu-action from 3 to 4 version (#1825)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-03-05 12:37:36 +01:00
Pavel Punsky
00519cd2b5
Perf: improve worst case scenario optimization (#1823)
Memory allocation performance optimizations:
- Replaced a heap-allocated buffer with a stack-allocated one in
generate_cookie():
- Optimized buffer reuse in the UDP server's packet receive loop -
reduces unnecessary allocations/frees in the hot path of the UDP batch
receive loop (especially during DDoS)
2026-03-01 20:57:33 -08:00
Pavel Punsky
ec0719c421
Fix compilation warnings (#1822)
Resolve multiple compilation warnings:
- unused argument
- type conversion
2026-02-28 19:45:16 -08:00
dependabot[bot]
b07d747d4b
Upgrade actions/download-artifact from 7 to 8 version (#1820)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-27 00:57:38 +01:00
dependabot[bot]
a56ee58ee5
Upgrade actions/upload-artifact from 6 to 7 version (#1819)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-02-27 00:56:53 +01:00
Pavel Punsky
35180707b9
Fix codeql scanning definition (#1814)
Language definition changed from cpp to c-cpp
2026-02-25 22:57:24 -08:00
tyranron
e4b7f09c00
Upgrade Docker image to 4.9.0 Coturn version docker/4.9.0-r0 2026-02-24 11:12:50 +02:00
Pavel Punsky
41ba6d8f5d
Update version to 4.9.0 (#1813)
Update version to 4.9.0 

Contains security fixes and highly recommended to upgrade
4.9.0
2026-02-23 17:04:31 -08:00
Pavel Punsky
e59f0ffeaa
Fix thread sanitizer warning (#1812)
Resolves all sanitizer warnings caused by
1. simultaneous access to logger time
2. barrier during threads initialization at startup
2026-02-23 16:16:27 -08:00
Pavel Punsky
da30d26ea3
Temporary workaround for windows build (#1811) 2026-02-22 22:57:29 -08:00
Pavel Punsky
b80eb898ba
Merge commit from fork
* Handle IN6_IS_ADDR_V4MAPPED mappings

* Handle IN6_IS_ADDR_V4MAPPED mappings
2026-02-22 19:18:42 -08:00
Pavel Punsky
e5ed78583d
Fixes: int to bool conversion and comparison (#1810)
In multiple places int is converted to bool
2026-02-21 18:27:16 -08:00
Pavel Punsky
4c674289a8
OpenSSL: migrate to modern API for DH param (#1809)
Use openssl-3.0 apis
2026-02-21 17:31:17 -08:00
Pavel Punsky
6c38ccb08d
Migrate AES-128 encryption from deprecated OpenSSL API to EVP (#1808)
The AES_encrypt, AES_set_encrypt_key, CRYPTO_ctr128_encrypt, and
SSL_CTX_use_RSAPrivateKey_file functions are deprecated in OpenSSL 3.0+
and produce compiler warnings.Replace deprecated low-level OpenSSL
AES/CRYPTO functions with the modern EVP (Envelope) API, and remove the
deprecated SSL_CTX_use_RSAPrivateKey_file fallback.

Changes
encrypt_aes_128 — Replaced AES_set_encrypt_key + CRYPTO_ctr128_encrypt
with EVP_EncryptInit_ex / EVP_EncryptUpdate / EVP_EncryptFinal_ex using
EVP_aes_128_ctr(). Added proper error handling (context cleanup on
failure), input length bounds checking, and enlarged the total buffer
from 256 to 1024 bytes to match the output buffer. The IV was corrected
from 8 to 16 bytes (as required by AES-CTR).

decrypt_aes_128 — Same migration from CRYPTO_ctr128_encrypt to
EVP_DecryptInit_ex / EVP_DecryptUpdate / EVP_DecryptFinal_ex. Added
proper cleanup of both the EVP context and the encryptedText allocation
on every error path. Retained the existing bounds check on newTotalSize.
Output is now explicitly null-terminated using the actual decrypted
length (outlen + final_len).

set_ctx (TLS context setup) — Removed the SSL_CTX_use_RSAPrivateKey_file
fallback that was nested inside the SSL_CTX_use_PrivateKey_file failure
path. SSL_CTX_use_PrivateKey_file already handles RSA keys, so the
RSA-specific fallback was redundant and used a function deprecated since
OpenSSL 3.0.
2026-02-19 18:05:05 -08:00
Pavel Punsky
b209191ba1
Fix unbounded strcpy in stun_method_str (ns_turn_msg.c) (#1798)
## Issue
strcpy(smethod, s) with no size check. Callers pass fixed buffers (e.g.
32 bytes); if API were misused with a smaller
buffer, or s were ever longer, this could overflow.

## Fix
Use strncpy with a fixed maximum (32), then null-terminate,
so at most 32 bytes are written regardless of caller buffer size.
2026-02-16 21:23:10 -08:00
Pavel Punsky
667b661e80
Fix missing null termination in addr_to_string (ns_turn_ioaddr.c) (#1806)
## Issue
Multiple changes in this PR related to address printing (with and
without port)
- Change buffer size to be 64 (enough to hold IPv6 - 46, and port - 5,
and formatting "[ip]:port")
- Align buffer size across all usages (were 65, 129, 256, 257, 1025).
Even 65 is bad - takes extra cache line.
- Change argument to `addr_to_string_no_port`/`addr_to_string` to be of
type char inasted of uint8_t (double converted)
- Eliminate extra buffer in `addr_to_string_no_port`
- Defensively terminate string with null in addr_to_string`

## Explanations
- `addr_to_string_no_port` rely on `inet_ntop` to convert address to
null terminated string
- `addr_to_string` with port==0 rely on `inet_ntop`, otherwise null
terminate at the end of the buffer of size MAX_IOA_ADDR_STRING
2026-02-16 21:20:41 -08:00
Pavel Punsky
77f99e0995
Fix missing null termination after strncpy in DB drivers (#1804)
## Issue
strncpy(realm/pwd, ..., STUN_MAX_*_SIZE) does not append a null. When DB
value length >= size, the buffer was
unterminated, leading to potential reads past buffer in later code.

## Fix
Explicitly set realm[STUN_MAX_REALM_SIZE] and pwd[STUN_MAX_PWD_SIZE] to
'\0' after each strncpy.
2026-02-16 19:19:02 -08:00
Pavel Punsky
ad85332c94
Fix unbounded strcpy in HTTP response (http_server.c) (#1800)
## Issue
strcpy(data, data_http) copied into the network buffer
with no size check. If buffer allocation or layout changed, this
could overflow.

## Fix
Use ioa_network_buffer_get_capacity(), copy at most that many
bytes with memcpy, explicitly null-terminate, and set size accordingly.
2026-02-15 18:48:24 -08:00
Pavel Punsky
8c8bf97a38
Remove ubuntu20, DEBUG builds from build matrix (#1803)
Random failures with tests including prometheus - no time to solve it
now so just disabling

Also, removing DEBUG targets from Windows builds
2026-02-15 18:38:39 -08:00
Pavel Punsky
84f492ad6e
Fix buffer overflow in decryptPassword in mysql (#1801)
## Issue
strcat(last, (char *)outdata) then strcpy(out, last) with last[1024].
outdata is not null-terminated (decryption output),
allowing reads past buffer and possible overflow of last.

## Fix
Use bounded memcpy with explicit null termination, limiting copy to
remaining space in last and sizeof(outdata). Check malloc before strcpy.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-15 18:22:56 -08:00
Pavel Punsky
bdacef780b
Fix missing null termination after strncpy in MongoDB driver (dbd_mongo.c) (#1797)
## Issue
strncpy(realm/pwd, ...) without null termination
when source is long left buffers unterminated.

## Fix
Set realm[STUN_MAX_REALM_SIZE] and pwd[STUN_MAX_PWD_SIZE]
to '\0' after each strncpy.
2026-02-15 17:50:40 -08:00
Pavel Punsky
b69ceb4252
Fix buffer overflow in decrypt_aes_128 (#1799)
**Issue**: 

strcat(last, (char *)outdata) was used with a fixed
buffer last[1024]. outdata is decryption output that is not
null-terminated (CRYPTO_ctr128_encrypt writes newTotalSize bytes). This
could read past outdata and/or overflow last if decrypted size grew.

**Fix**: 

Replace with bounded copy using memcpy and explicit null
termination, limiting bytes copied to remaining space in last and to
sizeof(outdata).
2026-02-15 17:42:01 -08:00
薄景仁
7f7dc99d3e
Urgent! Fix Web Admin Password Check (#1802)
The password check for web admin is reversed, so users can login with
the wrong password. 

Fixes #363, #1216
2026-02-12 21:09:12 -08:00
tyranron
8dc340f9be
Update Debian "trixie" to 20260202 snapshot in Docker image 2026-02-04 17:12:33 +02:00
tyranron
53c405a712
Update Alpine to 3.23.3 version to fix OpenSSL CVEs in Docker image
- CVE-2025-11187
- CVE-2025-15467
- CVE-2025-15468
- CVE-2025-15469
- CVE-2025-66199
- CVE-2025-68160
- CVE-2025-69418
- CVE-2025-69419
- CVE-2025-69420
- CVE-2025-69421
- CVE-2026-22795
- CVE-2026-22796
docker/4.8.0-r1
2026-01-29 12:42:56 +01:00
tyranron
80e20f58f3
Update Debian "trixie" to 20260112 snapshot in Docker image 2026-01-13 13:10:32 +01:00
tyranron
48fb3dd287
Upgrade Docker image to 4.8.0 Coturn version docker/4.8.0-r0 2026-01-06 16:48:21 +01:00
Pavel Punsky
0177bcd373
Update version to 4.8.0 (#1791)
Update version to 4.8.0 
Set new release version to 4.8.0

Contains security fixes and highly recommended to upgrade
4.8.0
2026-01-05 17:35:27 -08:00
tyranron
a7202a72dd
Update Debian "trixie" to 20251229 snapshot in Docker image 2025-12-30 12:33:55 +01:00
Pavel Punsky
11fc465f4b
Merge commit from fork
This returns the code to the state before #1279 that made turn_random() less secure and introduced more secure version with urn_random_number()  (which is actually the same as turn_random() before the change)
2025-12-29 09:05:16 -08:00
Pavel Punsky
bae6bb3aed
Allow faster packet validation on listener threads (#1768)
Add CLI flag to enable early packet validation
Drop packets that do not pass basic STUN command/channel or DTLS parsing

Before this change, no validation on packets were done and they were
passed (through libevent queue) to relay thread pool. Relay thread
would, for a new source, allocate a new SS (18KB) which will only be
released after 1s of no traffic, and then do the validation.

So with old code, invalid packet would have extra:
- Queuing
- Processing on a different thread
- Memory allocation of 18KB

Assuming DDoS attack is spoofing IPs it reduces processing capacity
dramatically.
Testing possible by:
```
hping3 -2 -p 3478 -d 2 -rand-source --flood turn_ip
```

which floods `turn_ip:3478` with packets of size 2 from random sources.
Size 2 is especially bad case - the packet is obviously invalid (too
short) but still goes through a long process of queuing, thread
switching, memory allocation and only then validation (and then memory
cleanup etc). In worst cases, memory is never cleaned up because sources
repeat.
2025-12-29 09:04:25 -08:00
Pavel Punsky
c7936e449b
Fix order of arguments to calloc (#1790)
Proper use of the api: count and then size
This gives a warning on some of the compilers
2025-12-28 11:39:01 -08:00
Pavel Punsky
21ddce65be
Fix crashes while setting socket buffer size (#1789)
Some places in code do not have access to the buffer size which result
in crash which can be seen in tests
This PR removes the call to `set_ioa_socket_buf_size` from those places
(which is redundant anyway)
2025-12-26 21:10:24 -08:00
Pavel Punsky
59921981bb
Implement configurable buffer sizes (#1780)
# Description

Replace the hardcoded buffer sizes inside coturn to make them
configurable for different use cases (low bitrate use cases can save
memory and high bitrate use case can avoid congestion) - based on #1089

Add this feature in both sides (listener and relay connections).

# Tests

For now it is only the automated CI tests.
Confirmed with debugger that buffer sizes are set according to the
arguments.
2025-12-25 14:06:28 -08:00
tyranron
6a0b3a648a
Update Alpine to 3.23.2 version in Docker image docker/4.7.0-r4 2025-12-18 14:44:24 +01:00
dependabot[bot]
15cecc97a2
Upgrade actions/download-artifact from 6 to 7 version (#1785)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-13 01:44:37 +01:00
dependabot[bot]
60ed2e246e
Upgrade actions/upload-artifact from 5 to 6 version (#1784)
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-12-13 01:43:51 +01:00