Repository navigation
Cherry pick #117003 to 26.3: Bound the MySQL handshake response - #118073
Merged
robot-clickhouse-ci-2 merged 12 commits intoSep 7, 2026
Merged
Conversation
On the TLS path the handshake response was read through `MySQLPacketPayloadReadBuffer`, which follows a chain of maximum-size packets as one logical message, and the fields inside the response are read up to a terminator. A peer that completed the TLS handshake could therefore stream data and make the server grow memory before sending any credentials. Bound the response on both paths: the plaintext path rejects a declared payload larger than 64 KiB before reading it, and the TLS path, where the framing is handled by the packet endpoint, reads through a buffer limited to the same size. A real handshake response is a few hundred bytes.
…path Address review: limiting the underlying stream under `PacketEndpoint` was not enough. `MySQLPacketPayloadReadBuffer` reports end of file as soon as the stream below it ends, and `IMySQLReadPacket::readPayload` treats that as "the whole packet was consumed", so a stream cut off exactly at the limit would make a truncated packet look like a complete one: a peer could declare a payload of `0xFFFFFF` and have the parsed prefix end at the limit. Read the packet header on the TLS path as well, reject a declared payload larger than the bound before reading it, and then read exactly as many bytes as the header declares, which mirrors the plaintext path. Add a test case for a packet that declares a maximum-size payload while carrying a complete, parseable prefix.
…ual transport state `mysql_require_secure_transport` was checked against the client-advertised `CLIENT_SSL` capability bit. A client can set that bit in a plaintext `HandshakeResponse` without ever sending an `SSLRequest`: it then stays on the non-TLS branch of `finishHandshake`, `secure_connection` remains false, and the gate still lets authentication proceed over cleartext. Key the check off `secure_connection`, which is set only when the TLS transition actually happened, and add a focused integration test that drives a plaintext handshake advertising `CLIENT_SSL` against a server with `mysql_require_secure_transport`.
The test used the `default` user, which needs a password, so the handshake was rejected by authentication rather than by the gate. Drive it with a `no_password` user instead: without the fix the server now replies with an OK packet on the unencrypted connection, which is exactly the bypass.
…ze-limit Bound the MySQL handshake response
Contributor
|
Dear @thevar1able, @alexey-milovidov, this cherry-pick PR has not been updated for 3d0h25m36s. Please resolve the conflicts to backport #117003, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #117003
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job