Repository navigation
Do not deserialize a Data packet that arrives before any query - #118588
alexey-milovidov merged 11 commits into
Conversation
TCPHandler::receivePacketsExpectQuery() handles the packets that arrive
before any Query has been received. Its Data/Scalar case called
processUnexpectedData() and only then threw UNEXPECTED_PACKET_FROM_CLIENT.
That call builds a headerless NativeReader and reads a block, so the
column type name comes off the wire and is handed to DataTypeFactory.
Entering interserver mode requires only the name of a cluster that has a
non-empty <secret>, never the secret itself, and the secret is verified
only inside processQuery(), which this loop never reaches. So an
unauthenticated peer decided which type the server constructed and which
deserializer ran.
The read had no consumer for any peer either: its return value was
discarded, and the exception thrown right after is caught where
"if (!query_state) return;" exits runImpl, so the exception is never
sent, the connection is closed, and no further byte is read from the
socket. runImpl's exception handler already documents that policy ("the
server should not try to skip (parse, decompress) the remaining packets
sent by the client, as it will lead to additional work and unneeded
exposure to unauthenticated connections"); the parse it forbids had
already happened one frame earlier. The adjacent case of the same
switch, processObsoleteIgnoredPartUUIDs(), was given exactly this shape
in ClickHouse#99398.
No setting gates the rejection, deliberately. The TablesStatusRequest
path needed an operator opt-out when it was hardened in ClickHouse#99854 because
it was a served path, and rejecting it broke rolling upgrades (ClickHouse#113602).
Data before Query has always thrown, so there is no working flow to
preserve, and nothing a client can observe changes: the connection
closes with nothing written back, before and after.
The regression test completes an accepted interserver handshake over a
raw socket and then sends a Data packet declaring a column type that
does not exist. Without this change the server logs "Unknown data type
family: NoSuchTypeGroeneAI", which is the proof that a wire-supplied
type name reached DataTypeFactory before authentication. It is extended
into the existing pre-authentication interserver test module rather than
added as a new one, because that module already provides the cluster
with a <secret> and a handshake pinned below the chunked-packets
revision, which is what makes a hand-built packet feasible.
Requested by @ nikitamikhaylov, relayed via OranjeAI.
Co-Authored-By: Claude Opus 5 <[email protected]>
The regression test sent the complete Data packet and then asserted only that no data type had been constructed. That is a subset of what the change claims: a handler that read the external table name and only then threw would touch peer-supplied payload bytes and still pass the test. The test function now opens a second connection that sends the Data packet type alone, one byte, and shuts down its write side. On a server without the fix the external-table-name length varint inside processUnexpectedData() hits end of stream, so UNEXPECTED_PACKET_FROM_CLIENT is never constructed and the rejection is never logged; measured, that arm fails with "Attempt to read after eof" raised from readStringBinary one frame below processUnexpectedData(). With the fix the rejection is immediate, because no payload byte is required. The handshake and the bounded log barrier are factored into helpers so the second connection reuses them; both are used by the new test only, and the two pre-existing tests keep their own inlined handshake unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
The native protocol spec describes READY as the state where the client may send Ping, Query or close, and, unlike the handshake, ping and query phases, it gives no outcome for anything else. A client author reading it cannot learn what happens if they send a Data packet there, which is precisely the packet this change stops the server from decoding. State the three facts: it is a protocol violation and the connection is terminated, no Exception packet is sent first so the client observes a silent close, and the body is not decoded. The silent close is general rather than interserver-specific: query_state is always null in the loop that reads pre-query packets, so runImpl's handler returns before any send for every peer. Scalar is named alongside Data because both share the same case label. The sentence is deliberately not written as "anything other than Ping or Query", which would be wrong: TablesStatusRequest is served from READY and Cancel is accepted and ignored. Co-Authored-By: Claude Opus 5 <[email protected]>
The module comment stated that a packet arriving before the Query must neither disclose anything nor have its payload deserialized. Two pre-query paths contradict that by design, not by omission: processTablesStatusRequest reads the request body before validating the hash, because the hash is computed over that body, and Ping is answered with Pong. A reader who takes the sentence as the module's invariant concludes the hardened TablesStatusRequest path is buggy. Scope the claim to the packets the server rejects. The legitimately served pre-query packets are not enumerated here; the protocol spec carries that. Co-Authored-By: Claude Opus 5 <[email protected]>
The module comment claimed that a packet the server rejects before the Query must disclose nothing and must not have its payload deserialized. The second half is false for two pre-query paths, one of which this very comment enumerates: processTablesStatusRequest() deserializes the request body at TCPHandler.cpp:1711 before comparing digests at :1738, because the digest binds request.getAuthDigest(), so a wrong-secret request is rejected only after its payload has been read. processUnexpectedHello() likewise drains seven bounded fields and then throws. A reader who checks the module's second bullet, a TablesStatusRequest signed with the wrong cluster secret, against the sentence above it finds them contradictory. Only a rejected Data or Scalar packet leaves its payload untouched, so the payload clause now names Data. The disclosure clause holds for every rejected packet and is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model reviewAn independent model reviewed the resulting code and I adjudicated its findings against the
One question for a maintainer: the sibling defect in this same file, #99854, shipped as |
|
Workflow [PR], commit [a5e177d] Summary: ✅
AI ReviewSummaryThis PR hardens Final Verdict✅ Approved. No remaining findings. LLVM Coverage ReportMeasured on commit a5e177d.
Changed lines: Changed C/C++ lines covered: 7/7 (100.00%) · Uncovered code |
|
cc @vitlibar @nikitamikhaylov, could you review this? In interserver mode the cluster secret is only verified while the |
CI finish ledger - 2ddbe6eEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Coverage, so the ledger is not certifying an untested head: 150 of 174 checks passed, 21 skipped, Session id: cron:our-pr-ci-monitor:20260907-213102 |
|
Fixing-PR link-back for the The logs-cluster user switch that addresses the |
The READY row of the protocol spec said the client "observes a silent close". The server rejects the packet without reading its body, so unconsumed bytes can still be queued when the socket closes and the client can see a TCP reset instead. The sibling reject-before-read path behaves the same way on master, which is why its test accepts ConnectionResetError. Stating the reset outcome keeps a client author from treating it as a protocol bug.
Both comments said the cluster secret is only verified while the Query packet is processed. That is not true: a new-protocol TablesStatusRequest validates a secret-derived hash of its own before any Query, which the module's wrong-secret test exercises. What stays unauthenticated until the Query packet is the connection, which is what is_interserver_authenticated tracks and what makes an early Data packet peer-controlled input.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes10 object files changed (+28.94 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 20 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 6de6981Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Nothing here is attributable to this pull request: its diff touches Session id: cron:our-pr-ci-monitor:20260908-123042 |
|
@groeneai merge master. |
|
Merged master ( |
…ation failure Not reading the payload is the point of the previous commit, but throwing `UNEXPECTED_PACKET_FROM_CLIENT` for it also renames the case: an interserver connection that has not reached its `Query` packet is unauthenticated, and `runImpl` has a dedicated answer for `AUTHENTICATION_FAILED` in interserver mode. Throw that instead, and keep `UNEXPECTED_PACKET_FROM_CLIENT` for an ordinary client. `CH Inc sync` found this: a test there asserts the guard's log line for exactly this shape, and it stopped appearing once the packet was rejected earlier. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A Data packet arriving before any Query on an unauthenticated interserver connection is now reported as AUTHENTICATION_FAILED, so "Unexpected packet Data received from client" is no longer logged on the path this test drives: both log barriers waited out their 60s timeout and the test failed even with the guard working. Measured here, the old needle never appears at all (assert 0 > 0 after 84s); the new one appears within the barrier, and the test passes 50/50. Matching the interserver wording rather than a signal shared by both exception codes keeps the assertion tied to the unauthenticated case: a connection that stopped reaching interserver mode would otherwise still satisfy it. With src/Server/TCPHandler.cpp reverted to master the test still reddens on the deserialization assertion (assert 1 == 0), so the oracle is no weaker than before. Co-Authored-By: Claude Opus 5 <[email protected]>
|
📊 Cloud Performance Report ✅ AI verdict: no significant changes detected. K_source=6 K_base=30 flagged=0/65 clickbench🟢 No significant changes tpch_adapted_1_official🟢 No significant changes Debug info
|
Backport #118588 to 26.7: Do not deserialize a Data packet that arrives before any query
Backport #118588 to 26.8: Do not deserialize a Data packet that arrives before any query
Cherry pick #118588 to 26.3: Do not deserialize a Data packet that arrives before any query
Resolve the cherry-pick of #118588 onto 26.6. The `TCPHandler.cpp` hunk and the `NativeProtocol` spec change merged cleanly (git followed the docs page rename to `docs/en/interfaces/specs/NativeProtocol.md`). `tests/integration/test_interserver_tables_status_auth` does not exist on 26.6: its `TablesStatusRequest` cases depend on `interserver_tables_status_require_auth`, which was introduced after the branch was cut. The module is therefore carried as a 26.6-local variant containing only the `Data`-before-`Query` regression test that #118588 added, with a single-node cluster config providing the `mismatch` secret. Co-Authored-By: Claude Fable 5.1 <[email protected]>
Cherry pick #118588 to 26.6: Do not deserialize a Data packet that arrives before any query
Backport #118588 to 26.6: Do not deserialize a Data packet that arrives before any query
Backport #118588 to 26.3: Do not deserialize a Data packet that arrives before any query
…that arrives before any query
…that arrives before any query
Related: #99854
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed the server deserializing the payload of a
Datapacket that arrives on a connection before any query. In interserver mode the connection is not authenticated until theQuerypacket is processed, so such a packet was rejected only after its Native block had been read, which let an unauthenticated peer choose the column type the server constructed. The packet is now rejected before its payload is touched.Description
TCPHandler::receivePacketsExpectQuery()handles packets arriving before anyQuery. ItsData/Scalarcase calledprocessUnexpectedData()and only then threwUNEXPECTED_PACKET_FROM_CLIENT. That call reads a block through a headerlessNativeReader, so the column type name goes off the wire intoDataTypeFactory::get().Entering interserver mode requires only the name of a cluster with a non-empty
<secret>, never the secret itself; the connection is authenticated only insideprocessQuery(). So an unauthenticated peer chose which deserializer ran.The read had no consumer for any peer: its result was discarded, and the exception that follows is caught where
if (!query_state) return;exitsrunImpl, so nothing is sent and no further byte is read.runImpl's exception handler already states that policy ("unneeded exposure to unauthenticated connections"); the parse it forbids had already happened. The adjacent case of this switch,processObsoleteIgnoredPartUUIDs(), was given this shape in #99398.Removing the call is the fix, and no setting is added: unlike the
TablesStatusRequestpath in #99854, which was served and needed an opt-out (#113602),DatabeforeQueryhas always thrown, so there is no working flow to preserve and nothing a legitimate client observes changes. The protocol spec'sREADYrow now records this rejection.Requested by @ nikitamikhaylov (relayed privately, so there is no public issue to link).
Validation: a new integration test completes an accepted interserver handshake, then sends a
Datapacket declaring a nonexistent type. Without this change the server logsUnknown data type family: ..., proving a wire-supplied type name reachedDataTypeFactorypre-authentication; with it the packet is rejected unread. 30/30 repeats green.Two adjacent surfaces stay untouched.
processUnexpectedHello()also drains its packet, but every field is capped byMAX_HELLO_STRING_SIZEand none reaches a factory.processQuery()deserializesclient_infoandSettingsbefore the hash check, which the protocol requires: the hash covers the query text.Workflow [PR]
Sync PR [sync-upstream/pr/118588]
Version info
26.9.1.1316(included in26.9and later)26.8.3.103,26.7.7.91,26.6.5.120,26.3.33.69