Skip to content

RabbitMQ related fix - #112479

Merged
kssenii merged 15 commits into
masterfrom
fix-amqp-cpp-frame-max-oob
Aug 12, 2026
Merged

kssenii merged 15 commits into
masterfrom
fix-amqp-cpp-frame-max-oob

Conversation

@kssenii

@kssenii kssenii commented Jul 29, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

RabbitMQ Security related bugfix.

Version info

  • Merged into: 26.8.1.1209 (included in 26.8 and later)
  • Backported to: 26.7.4.26, 26.6.3.31, 26.3.33.12

`CREATE TABLE ... ENGINE = RabbitMQ` connects to the broker synchronously, so the whole
AMQP handshake runs while the statement is being executed. A broker can answer the
handshake with a `Connection.Tune` frame proposing a maximum frame size of zero, which
in AMQP means "no limit". `AMQP-CPP` stored that verbatim and uses the maximum frame
size both as the capacity of its receive buffer and as the bound that incoming frames
are validated against, so zero disabled the bound while the buffer stayed at its
initial 4096 bytes. The broker could then announce a frame with a payload of up to
`0xFFFFFFFF` bytes and have the client read that many bytes into the 4096-byte
allocation - a heap out-of-bounds write with remotely controlled length and content.

The fix is in the `contrib/AMQP-CPP` submodule: the negotiated maximum frame size is
never allowed below the protocol minimum, an oversized frame is rejected even when the
negotiated maximum is zero, and the receive buffer now clamps every read to the memory
it has actually allocated.

`remote_host_filter` is applied to `rabbitmq_address` as well. It used to be checked
only for `rabbitmq_host_port`, so an authenticated user could reach a host outside the
allowlist just by spelling the same address in the URI form.

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

clickhouse-gh Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [77938e1]

Summary: ❌

job_name test_name status info comment
Stress test (arm_asan_ubsan) FAIL
Sanitizer (STID: 1367-26c6) FAIL cidb, issue ISSUE EXISTS

AI Review

Summary

This PR hardens the RabbitMQ engine against hostile AMQP frame_max negotiation, extends remote_url_allow_hosts checks to rabbitmq_address, and tightens the TLS semantics around rabbitmq_secure versus URI-form addresses. The AMQP-CPP and regression-test coverage are directionally good, but the rabbitmq_secure downgrade is still reachable through a fresh full ATTACH, so the security fix is incomplete.

PR Metadata
  • 💡 Changelog category: Bug Fix matches the change.
  • 💡 Changelog entry: required, but Security related bugfix. is too vague. Suggested replacement: Fixed the \RabbitMQ` table engine to reject malicious AMQP `frame_max` negotiation, apply `remote_url_allow_hosts` to `rabbitmq_address`, and reject contradictory `rabbitmq_secure = 1` with plaintext `amqp://` on fresh `CREATE TABLE`.`
Findings

❌ Blockers

  • [src/Storages/RabbitMQ/StorageRabbitMQ.cpp:185] The new contradiction check is keyed only on mode <= LoadingStrictnessLevel::CREATE, but a full user ATTACH TABLE ... ENGINE = RabbitMQ ... reaches this constructor with mode == LoadingStrictnessLevel::ATTACH and is still accepted by InterpreterCreateQuery. In that path the exception is skipped, secure_connection is overwritten from the URI to false, and RabbitMQConnection::connectImpl still opens the plaintext amqp:// connection even though the user asked for rabbitmq_secure = 1. That leaves the silent TLS downgrade reachable for fresh user-supplied definitions while the updated docs now promise rejection. Suggested fix: distinguish metadata replay / short attach from a fresh user ATTACH the same way other storages do, e.g. via args.query.attach_short_syntax or isLoadingFromExistingMetadata(args.mode) in the storage creator, instead of exempting every ATTACH.
Tests
  • ⚠️ Add a focused regression for a full user ATTACH TABLE ... ENGINE = RabbitMQ ... SETTINGS rabbitmq_address = 'amqp://...', rabbitmq_secure = 1 and assert that it is rejected, while a short ATTACH TABLE t; or startup replay of old metadata still loads. The current suite covers only CREATE, so it misses the remaining downgrade path.
Final Verdict

Changes requested: narrow the ATTACH carveout to metadata replay only; do not keep the plaintext downgrade reachable for fresh user-supplied ATTACH definitions.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.70% 86.70% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.00% 79.00% +0.00%

Changed lines: Changed C/C++ lines covered: 37/43 (86.05%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-bugfix Pull request with bugfix, not backported by default submodule changed At least one submodule changed in this PR. labels Jul 29, 2026
kssenii and others added 2 commits July 30, 2026 09:05
…ress

`RabbitMQConnection::connectImpl` connects to `rabbitmq_address` (the URI form)
whenever it is set, in preference to `rabbitmq_host_port`, and `connection_string`
is always filled from `rabbitmq_address`. The constructor, however, validated
`rabbitmq_host_port` first and only checked `rabbitmq_address` in the `else`
branch, so a user could pair an allowed `rabbitmq_host_port` with a disallowed
`rabbitmq_address` (both settings are accepted together) and still connect to the
unvalidated host, bypassing `remote_url_allow_hosts`.

Validate against `remote_host_filter` by keying off the same condition
`connectImpl` uses: check `rabbitmq_address` whenever it is set, falling back to
`rabbitmq_host_port` only when there is no address. `connection_string` now reuses
the exact validated string.

Regression test: an allowed `rabbitmq_host_port` plus a disallowed
`rabbitmq_address` is now rejected with `UNACCEPTABLE_URL`.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Follow-ups from review of the RabbitMQ malicious-broker fix:

* Bump contrib/AMQP-CPP to aba8fac: clamp the negotiated max frame size from
  above (a peer proposing frame_max close to 2^32-1 could otherwise make us
  allocate multiple gigabytes for the receive buffer), and stop TcpInBuffer
  from recording capacity for a buffer that malloc failed to allocate.

* Initialize OpenSSL when the connection is TLS because `rabbitmq_address` uses
  the `amqps` scheme, not only when the `rabbitmq_secure` setting is set.

* Strengthen the frame_max=0 test to assert that the library logs the
  `frame size exceeded` protocol error, a deterministic proof that the guard
  fired rather than the server merely surviving the overflow by luck on a
  non-sanitizer build.

* Add an `amqps` variant of the malicious-broker test that drives the same
  overflow through the previously unclamped TLS receive path.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
.secure = (*rabbitmq_settings)[RabbitMQSetting::rabbitmq_secure].value,
.connection_string = getContext()->getMacros()->expand((*rabbitmq_settings)[RabbitMQSetting::rabbitmq_address])
.connection_string = address_string
};

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_secure = 1 is still ignored when rabbitmq_address is set. configuration.secure only reaches AMQP::Address(host, port, ..., secure) in the host/port branch; once connection_string is non-empty, RabbitMQConnection::connectImpl reparses the URI and drops this flag entirely (src/Storages/RabbitMQ/RabbitMQConnection.cpp:94-104). The public docs still say "Use either rabbitmq_secure = 1 or amqps" (docs/en/engines/table-engines/integrations/rabbitmq.md:85), so rabbitmq_address = 'amqp://...' plus rabbitmq_secure = 1 silently stays plaintext.

Please either reject that combination up front, or apply the secure flag when constructing the URI-form AMQP::Address, and add a regression test for the rabbitmq_address + rabbitmq_secure path.

For the `rabbitmq_address` form, `RabbitMQConnection::connectImpl` takes the
transport from the URI scheme and never applies `configuration.secure`, so
`rabbitmq_address = 'amqp://...'` together with `rabbitmq_secure = 1` silently
connected in cleartext despite the user asking for TLS - a silent security
downgrade.

Reject that contradiction with `BAD_ARGUMENTS` instead of downgrading (rather
than trying to "upgrade" the URI, which is ambiguous: `amqp://host` with no
port would connect TLS to the plaintext default port 5672). TLS with the
address form must be expressed with an `amqps://` scheme.

Add a regression test and clarify the docs: `rabbitmq_secure` applies to the
`rabbitmq_host_port` form; the address form selects the transport via its
scheme.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@mintlify

mintlify Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
ClickHouse-docs 🟢 Ready View Preview Jul 30, 2026, 9:10 AM

@kssenii
kssenii marked this pull request as ready for review July 30, 2026 12:58
@clickhouse-gh

clickhouse-gh Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.40% 86.50% +0.10%
Functions 91.80% 91.90% +0.10%
Branches 78.50% 78.60% +0.10%

Changed lines: Changed C/C++ lines covered: 24/32 (75.00%) · Uncovered code

Full report · Diff report

@arsenmuk arsenmuk self-assigned this Aug 4, 2026
…max-oob

# Conflicts:
#	docs/en/engines/table-engines/integrations/rabbitmq.md

@arsenmuk arsenmuk left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm with a new minor findings


Required parameters:

- `rabbitmq_host_port` – host:port (for example, `localhost:5672`).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As I understand, rabbitmq_address now becomes an equivalent alternative to rabbitmq_host_port, so it needs to be dragged up here, and we need to state that one of each / or both allowed

The `SSL connection` section of `rabbitmq.mdx` sits inside the
`AUTOGENERATED` region of the generated documentation tree, so the
edit does not belong in this pull request.

Co-Authored-By: Claude Opus 5 <[email protected]>
kssenii and others added 2 commits August 5, 2026 15:33
… truth

- The autogenerated rabbitmq.mdx was edited during conflict resolution
  while its source of truth, the documentation block in
  StorageRabbitMQ.cpp, still described the old TLS contract. Update the
  embedded documentation so regeneration is idempotent and the Mintlify
  docs check passes, and apply the suggested wording for the
  `rabbitmq_address` description (URI form, precedence over
  `rabbitmq_host_port`, remote_url_allow_hosts check) and the SSL
  connection paragraph.
  #112479 (comment)
  #112479 (comment)
  #112479 (comment)
- The amqps regression only proved the server survived. Now it records
  the count of `frame size exceeded` log lines before connecting and
  requires the count to grow, proving the frame-size guard fired on the
  TLS receive path as well. Counting (not substring presence) because
  the plaintext test already logs the same line into the shared log.
  #112479 (comment)
- The malicious broker now parses the client's Connection.TuneOk reply
  and logs the negotiated frame_max, and the tests assert it against the
  expected clamp: a frame_max=0 proposal must be answered with 4096
  (checked on both the plaintext and TLS paths), and a new test with a
  broker proposing 2^32-1 checks the reply is capped at 128 MiB. The
  TuneOk reply is what bounds the receive buffer, so echoing a hostile
  proposal back would let the broker announce frames of arbitrary size.
  #112479 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
The edited sections of rabbitmq.mdx sit inside the AUTOGENERATED region
of the generated documentation tree, which the Mintlify docs check
rejects when edited manually. The wording changes stay in the
documentation block of StorageRabbitMQ.cpp, the source of truth from
which the page is regenerated.

Co-Authored-By: Claude Fable 5 <[email protected]>
Comment thread contrib/AMQP-CPP Resolved
…allocated

Address review: with the initial 4 KiB TcpInBuffer allocation failed,
both receivefrom overloads computed a zero read size but still formed
`_data + _size` from a null buffer and passed it to read/SSL_read.
Short-circuit before forming the pointer and report the receive failure
explicitly (errno = ENOMEM, negative result).

#112479 (comment)

Co-Authored-By: Claude Fable 5 <[email protected]>
kssenii and others added 2 commits August 10, 2026 14:40
`conn.recv(65536)` is not frame-aware: on TCP/TLS it can return any positive
prefix of `Connection.StartOk`. When it returned only a prefix, the following
`recv_exactly(7)` for `Connection.TuneOk` started in the middle of `StartOk`,
the stream desynced, and the `client_frame_max` assertion became flaky.

Factor a `read_frame` helper (7-byte header + payload + end octet, all via
`recv_exactly`) and use it for both `StartOk` and `TuneOk` so the broker always
consumes exactly one whole frame and stays aligned.

Verified with a fragmented-`StartOk` client harness: the old broker fails to
parse the subsequent `TuneOk`, the new one parses it correctly.

#112479 (comment)

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@tavplubix tavplubix added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Aug 11, 2026
kssenii and others added 2 commits August 11, 2026 22:24
The `rabbitmq_secure = 1` vs plaintext `amqp://` `rabbitmq_address` contradiction
is rejected only for a fresh CREATE (`mode <= LoadingStrictnessLevel::CREATE`), so
an existing table that used this (previously accepted, silently plaintext)
combination still attaches after an upgrade instead of failing to load.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
`configuration.secure` was taken straight from the `rabbitmq_secure` setting, so
it disagreed with reality when `rabbitmq_secure = 0` but the `rabbitmq_address`
URI used the `amqps` scheme. Use `secure_connection`, which reflects the actual
transport (setting for the host/port form, URI scheme for the address form).

No behavioural change today - `connectImpl` derives the transport from the URI
for the address form and this field is only read on the host/port form, where
`secure_connection` equals the setting - but it keeps the field truthful.

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

clickhouse-gh Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 77938e116 with master 45ccfdfc8 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of c6eaf567f; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 691.36 MiB 688.36 MiB -3.00 MiB (-0.43%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes

5 object files changed (+19.66 KiB total), 0 added.

Object file Master PR Δ
src/CMakeFiles/dbms.dir/Storages/RabbitMQ/StorageRabbitMQ.cpp.o 879.94 KiB 899.06 KiB +19.12 KiB (+2.17%)

737 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

29 translation units recompiled, 78 s compile time in total, 27 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.63 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +17.1 s (+30%) in total before that adjustment.

Translation unit Master PR Δ vs median
src/Storages/RabbitMQ/StorageRabbitMQ.cpp 12.5 s 13.4 s -7.1 s (-35%)

Job report

@kssenii
kssenii added this pull request to the merge queue Aug 12, 2026
Merged via the queue into master with commit 4bd387a Aug 12, 2026
178 of 180 checks passed
@kssenii
kssenii deleted the fix-amqp-cpp-frame-max-oob branch August 12, 2026 08:26
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Aug 12, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 12, 2026
kssenii added a commit that referenced this pull request Aug 13, 2026
kssenii added a commit that referenced this pull request Aug 13, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Aug 22, 2026
@robot-ch-test-poll robot-ch-test-poll removed the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 7, 2026
robot-ch-test-poll added a commit that referenced this pull request Sep 7, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 7, 2026
rschu1ze added a commit that referenced this pull request Sep 8, 2026
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Sep 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default 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 submodule changed At least one submodule changed in this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants