Skip to content

Validate rabbitmq_routing_key_list in the RabbitMQ engine - #125661

Merged
alexey-milovidov merged 3 commits into
masterfrom
fix-rabbitmq-routing-key-validation
Oct 14, 2026
Merged

alexey-milovidov merged 3 commits into
masterfrom
fix-rabbitmq-routing-key-validation

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

For the headers exchange type, StorageRabbitMQ::bindExchange and RabbitMQProducer split each routing key on = and read the second part unconditionally. A key without = (e.g. rabbitmq_routing_key_list = 'format,logs') caused an out-of-bounds read, terminating the server process on a libc++ hardening assertion.

Such keys are now rejected at table creation with BAD_ARGUMENTS, before connecting to the broker. Keys whose value contains = are still accepted as before.

An explicitly empty rabbitmq_routing_key_list caused the same kind of out-of-bounds read of routing_keys[0] when binding and publishing. An empty list is a valid configuration (e.g. fanout, or rabbitmq_queue_consume = 1), so it is now treated as a single empty routing key.

The problem was found and reported by @dstesk (https://github.com/dstesk).

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fixed a server crash when a RabbitMQ table with the headers exchange type had a routing key without =, or when rabbitmq_routing_key_list was empty. Routing keys without = for the headers exchange type are now rejected with an exception. The problem was found and reported by @dstesk (https://github.com/dstesk).

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/125661]

Version info

  • Merged into: 26.10.1.2404-master (included in 26.10 and later)
  • Backported to: 26.9.20.9, 26.8.28.9, 26.7.31.10, 26.3.52.7

For the `headers` exchange type, `StorageRabbitMQ::bindExchange` and
`RabbitMQProducer` split each routing key on `=` and read the second part
unconditionally, so a key without `=` caused an out-of-bounds read
(a libc++ hardening assertion and process termination).

An explicitly empty `rabbitmq_routing_key_list` caused the same kind of
out-of-bounds read of `routing_keys[0]` for binding and publishing.

Reject both at table creation with `BAD_ARGUMENTS`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3d71ad8]

Summary: ✅


AI Review

Summary

The PR prevents out-of-bounds routing-key accesses in RabbitMQ by validating header keys and normalizing empty lists. One compatibility regression from the prior review remains: valid direct queue consumers using headers and an empty routing list are rejected, including when loading existing metadata. ❌ Block until this path is preserved and regression coverage is added.

Findings

❌ Blockers

  • src/Storages/RabbitMQ/StorageRabbitMQ.cpp:158–168: Direct queue consumption must continue accepting unused routing keys. With rabbitmq_exchange_type = 'headers', rabbitmq_queue_consume = 1, and rabbitmq_routing_key_list = '', normalization inserts an empty string and validation immediately throws BAD_ARGUMENTS. Previously, StorageRabbitMQ::initRabbitMQ consumed rabbitmq_queue_base without calling bindExchange, so this was valid. The same validation rejects the unchanged default routing key (5672) in this mode. Because the constructor applies the check during ATTACH and metadata loading too, existing consumers fail to load after an upgrade. Preserve unused routing keys on the consume path; validate header entries before actual binding or producer parsing, without synthesizing a malformed header for an empty header set. This is the remaining issue in the existing review thread, whose claimed fix is incomplete.
Missing context / blind spots
  • ⚠️ No local ClickHouse executable or configured build is available. The finding follows the verified PR-head source and metadata-loading path. The targeted stateless CI report returned no test results; a completed run of 05322_rabbitmq_invalid_routing_keys would close that runtime-validation gap.
Tests
  • ⚠️ The added stateless test covers only malformed header rejection; no test exercises the empty-list fix. Add small cases to the existing RabbitMQ integration module proving empty-list fanout binding/publishing and headers direct queue consumption, including reattachment of the consumer. These must verify successful message delivery as well as successful creation.
Final Verdict

❌ Block. Preserve valid headers direct queue consumers through creation and metadata loading, retain safe validation before header parsing, and add focused empty-list regression coverage.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Oct 13, 2026

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@alexey-milovidov alexey-milovidov self-assigned this Oct 13, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). label Oct 13, 2026
[](const String & name) { return name.starts_with(deadletter_exchange_setting); });

/// The first routing key is used unconditionally for binding and publishing.
if (routing_keys.empty())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rabbitmq_routing_key_list is not universally required. With rabbitmq_queue_consume = 1, StorageRabbitMQ::initRabbitMQ skips bindExchange on the read path and consumes directly from queue_base; for fanout, RabbitMQ ignores the routing key anyway. This unconditional check turns those configurations into BAD_ARGUMENTS even though the only invariant we need here is “do not dereference routing_keys[0] when the list is empty”.

Could we normalize the empty case to "" (or gate the check to modes that actually use a routing key) instead of rejecting every empty value up front?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Agreed. An empty rabbitmq_routing_key_list is now normalized to a single empty routing key, so it is accepted again and routing_keys[0] is still always valid. The empty-list test case was removed because table creation now goes on to connect to the broker. Fixed in 3d71ad8 (commit "Address review: treat empty rabbitmq_routing_key_list as one empty key").

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The claimed empty-list fix is still incomplete for rabbitmq_exchange_type = 'headers', rabbitmq_queue_consume = 1, rabbitmq_routing_key_list = ''. At StorageRabbitMQ.cpp:158–168, normalization creates routing_keys = {""}, then the header validation throws BAD_ARGUMENTS because that synthetic entry has no =. This configuration previously consumed rabbitmq_queue_base without binding an exchange (StorageRabbitMQ::initRabbitMQ, lines 514–517). The new check also runs during ATTACH, so existing tables using it fail to load after upgrading.

Preserve empty header sets for direct queue consumption, enforce header validation at the binding/producer parsing boundaries, and cover creation plus reattachment in the existing RabbitMQ integration suite.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a different problem. The goal of this PR is to fix an out-of-bounds read.

alexey-milovidov and others added 2 commits October 14, 2026 03:42
An empty routing key list is a valid configuration (e.g. `fanout` ignores
the routing key and `rabbitmq_queue_consume = 1` does not bind at all), so
instead of rejecting it, normalize it to a single empty routing key. This
still avoids the out-of-bounds read of `routing_keys[0]`.

Also fix the `readability-container-contains` clang-tidy error reported in
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=125661&sha=d708b14288566a3fdde0a8120dd32c7eee1fd1ea&name_0=PR&name_1=Build%20%28arm_tidy%2C%201%2F4%29
PR: #125661

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 14, 2026
Merged via the queue into master with commit 2975dad Oct 14, 2026
348 of 349 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-rabbitmq-routing-key-validation branch October 14, 2026 20:40
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 14, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 14, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 14, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 14, 2026
Backport #125661 to 26.9: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
clickhouse-gh Bot added a commit that referenced this pull request Oct 14, 2026
Backport #125661 to 26.8: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
clickhouse-gh Bot added a commit that referenced this pull request Oct 14, 2026
Backport #125661 to 26.7: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
alexey-milovidov added a commit that referenced this pull request Oct 15, 2026
Backport #125661 to 26.3: Validate `rabbitmq_routing_key_list` in the `RabbitMQ` engine
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-message-queues Message queue integrations (Kafka, RabbitMQ, NATS table engines for stream ingestion/egress). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants