Repository navigation
Cap pre-auth Hello packet strings to 64 KB and limit handshake time - #103284
Conversation
An unauthenticated TCP client can allocate excessive server memory per connection by sending a crafted Hello packet with oversized string fields. Each `readStringBinary` call in `receiveHello` uses a default max size of 1 GiB (`DEFAULT_MAX_STRING_SIZE`), and all string fields are read before any authentication check. This caps all pre-auth `readStringBinary` calls to 64 KB using the existing `max_string_size` parameter, and adds a wall-clock handshake timeout (`handshake_timeout_milliseconds`) to prevent slowloris-style attacks from holding a thread indefinitely. Backport of ClickHouse/clickhouse-private#52882. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Workflow [PR], commit [18b907f] Summary: ❌
AI ReviewSummaryThis PR hardens the TCP pre-auth handshake by capping PR Metadata
Exact replacement text (PR body Documentation entry): Findings💡 Nits
ClickHouse Rules
Final VerdictStatus: Minimum required action:
|
| DECLARE(Float, distributed_cache_keep_up_free_connections_ratio, 0.1f, "Soft limit for number of active connection distributed cache will try to keep free. After the number of free connections goes below distributed_cache_keep_up_free_connections_ratio * max_connections, connections with oldest activity will be closed until the number goes above the limit.", 0) \ | ||
| DECLARE(UInt64, tcp_close_connection_after_queries_num, 0, R"(Maximum number of queries allowed per TCP connection before the connection is closed. Set to 0 for unlimited queries.)", 0) \ | ||
| DECLARE(UInt64, tcp_close_connection_after_queries_seconds, 0, R"(Maximum lifetime of a TCP connection in seconds before it is closed. Set to 0 for unlimited connection lifetime.)", 0) \ | ||
| DECLARE(UInt64, handshake_timeout_milliseconds, 30000, R"(Wall-clock timeout in milliseconds for the entire TCP handshake phase (Hello + Addendum). Limits how long an unauthenticated connection can hold a thread. Set to 0 to disable.)", 0) \ |
There was a problem hiding this comment.
The new setting default here is 30000, but the PR description's "Documentation entry" says default 10000. Please align the PR metadata/docs text with the actual default to avoid user confusion when copying configuration values.
LLVM Coverage Report
Changed lines: 93.75% (60/64) | lost baseline coverage: 3 line(s) · Uncovered code |
|
Hi — this PR may need backporting to Affected code: TCPHandler::receiveHello, receiveAddendum, processClusterNameAndSalt, processUnexpectedHello — core code present in all supported branches. Why: Security fix: unauthenticated TCP clients can allocate up to 4 GiB per connection (4 strings x 1 GiB each) before any auth check. TCPHandler::receiveHello has existed since the project began (git log shows TCPHandler.cpp added in commit 5b858de, 2020). The vulnerability exists in all supported branches. If this should be backported, consider adding |
Cherry pick #103284 to 26.1: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
…and limit handshake time
Cherry pick #103284 to 26.2: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
…and limit handshake time
Cherry pick #103284 to 26.3: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
…and limit handshake time
Cherry pick #103284 to 26.4: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
…and limit handshake time
The cherry-pick of #103284 dropped the `DECLARE(UInt64, handshake_timeout_milliseconds, ...)` line from `src/Core/ServerSettings.cpp` while keeping the matching `extern` in `src/Server/TCPHandler.cpp`. As a result, all `Build` jobs on this backport fail with: ld.lld-21: error: undefined symbol: DB::ServerSetting::handshake_timeout_milliseconds >>> referenced by TCPHandler.cpp:360 (TCPHandler.cpp.o) Re-add the missing declaration. On `master` and on the `26.4` branch the same line is already present (it landed earlier via the sync PR #103269), so this commit only changes the older release branches where the cherry-pick lost it.
The cherry-pick of #103284 dropped the `DECLARE(UInt64, handshake_timeout_milliseconds, ...)` line from `src/Core/ServerSettings.cpp` while keeping the matching `extern` in `src/Server/TCPHandler.cpp`. As a result, all `Build` jobs on this backport fail with: ld.lld-21: error: undefined symbol: DB::ServerSetting::handshake_timeout_milliseconds >>> referenced by TCPHandler.cpp:360 (TCPHandler.cpp.o) Re-add the missing declaration. On `master` and on the `26.4` branch the same line is already present (it landed earlier via the sync PR #103269), so this commit only changes the older release branches where the cherry-pick lost it.
The cherry-pick of #103284 dropped the `DECLARE(UInt64, handshake_timeout_milliseconds, ...)` line from `src/Core/ServerSettings.cpp` while keeping the matching `extern` in `src/Server/TCPHandler.cpp`. As a result, all `Build` jobs on this backport fail with: ld.lld-21: error: undefined symbol: DB::ServerSetting::handshake_timeout_milliseconds >>> referenced by TCPHandler.cpp:360 (TCPHandler.cpp.o) Re-add the missing declaration. On `master` and on the `26.4` branch the same line is already present (it landed earlier via the sync PR #103269), so this commit only changes the older release branches where the cherry-pick lost it.
Backport #103284 to 26.4: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
Backport #103284 to 26.2: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
Backport #103284 to 26.1: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
Backport #103284 to 26.3: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
… to 64 KB and limit handshake time
…3284 Backport ClickHouse#103284 to 26.4: Cap pre-auth Hello packet strings to 64 KB and limit handshake time
An unauthenticated TCP client can allocate excessive server memory per connection by sending a crafted Hello packet with oversized string fields. Each
readStringBinarycall inreceiveHellouses a default max size of 1 GiB (DEFAULT_MAX_STRING_SIZE), and all string fields are read before any authentication check.This caps all pre-auth
readStringBinarycalls to 64 KB and adds a wall-clock handshake timeout (handshake_timeout_milliseconds, default 10 000 ms) to prevent slowloris-style attacks.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Cap pre-auth TCP Hello packet strings to 64 KB and add
handshake_timeout_millisecondsserver setting to limit total handshake time, preventing unauthenticated clients from consuming excessive memory or holding threads indefinitely.Documentation entry for user-facing changes
New server setting
handshake_timeout_milliseconds(default: 10000). When set, limits the total wall-clock time for the TCP handshake phase (Hello + Addendum). Connections exceeding this timeout are closed.Version info
26.5.1.1026.4.1.1119,26.3.10.39,26.2.17.24,26.1.12.20