Skip to content

Fix MySQL dictionary source bypassing RemoteHostFilter for inline DDL params - #99720

Merged
tiandiwonder merged 5 commits into
ClickHouse:masterfrom
tiandiwonder:fix_mysql_bypass_remote_host_filter
Mar 19, 2026
Merged

tiandiwonder merged 5 commits into
ClickHouse:masterfrom
tiandiwonder:fix_mysql_bypass_remote_host_filter

Conversation

@tiandiwonder

@tiandiwonder tiandiwonder commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor
When a dictionary with `SOURCE(MYSQL(...))` is created via DDL using inline
parameters (not a named collection), `RemoteHostFilter` (`remote_url_allow_hosts`)
was never checked. A user with `CREATE DICTIONARY` privilege could use this to
probe arbitrary internal hosts (SSRF).

The named collection branch already called `checkHostAndPort` correctly. The
config-based `else` branch (DDL inline params) had no such check. Add it before
the `mysqlxx::PoolWithFailover` is constructed, covering both the single-host
case and the multi-replica `REPLICA(...)` case (mirroring the key iteration
logic in `PoolWithFailover.cpp:66-85`).

Add two integration tests in `test_allowed_url_from_config` that use `node5`
(empty `remote_url_allow_hosts`, all hosts denied):
- `test_mysql_dictionary_host_filter`: single `HOST` parameter
- `test_mysql_dictionary_replica_host_filter`: multiple `REPLICA(...)` blocks

Both tests do not require a running MySQL server — the host filter exception is
raised before any TCP connection is attempted.

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):

Fix MySQL dictionary source bypassing RemoteHostFilter for inline DDL params.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.3.1.833 (included in 26.3 and later)
  • Backported to: 25.8.29.15

@clickhouse-gh

clickhouse-gh Bot commented Mar 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [993b6e0]

Summary: ✅


AI Review

Summary

This PR closes an SSRF gap in MySQL dictionary DDL by adding RemoteHostFilter::checkHostAndPort validation for inline SOURCE(MYSQL(...)) parameters, including REPLICA(...) form, before pool creation. The change is narrowly scoped and the added integration tests cover both single-host and multi-replica paths. I did not find blocker/major correctness, safety, or performance issues in the patch.

Missing context

  • ⚠️ No CI report/log links were provided in the review request context, so this review is code-and-test-diff based.

ClickHouse Rules

Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
Safe rollout ✅
Compilation time ✅

Final Verdict

  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Mar 17, 2026
@serxa serxa self-assigned this Mar 17, 2026
@tiandiwonder
tiandiwonder enabled auto-merge March 18, 2026 10:33
@clickhouse-gh

clickhouse-gh Bot commented Mar 19, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 100.00% (29/29, 0 noise lines excluded)
Diff coverage report
Uncovered code

@tiandiwonder
tiandiwonder added this pull request to the merge queue Mar 19, 2026
Merged via the queue into ClickHouse:master with commit 3f1d923 Mar 19, 2026
159 checks passed
@tiandiwonder
tiandiwonder deleted the fix_mysql_bypass_remote_host_filter branch March 19, 2026 03:50
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 19, 2026
@tavplubix tavplubix added pr-must-backport Pull request should be backported intentionally. Use this label with great care! v25.12-must-backport v26.2-must-backport labels Jul 3, 2026
@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 Jul 3, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 3, 2026
tiandiwonder added a commit that referenced this pull request Jul 13, 2026
Backport #99720 to 25.8: Fix MySQL dictionary source bypassing `RemoteHostFilter` for inline DDL params
joelynch pushed a commit to aiven/ClickHouse that referenced this pull request Aug 17, 2026
…ing `RemoteHostFilter` for inline DDL params
alexey-milovidov pushed a commit to groeneai/ClickHouse that referenced this pull request Oct 28, 2026
…riting the top-level `PORT`

The DDL host-filter check added in ClickHouse#99720 validated a `REPLICA(...)` entry
without its own `PORT` against the default port 3306, while `mysqlxx::Pool`
resolves the effective replica port with fallback to the top-level `PORT`.
So `SOURCE(MYSQL(PORT 3307 ... REPLICA(HOST 'h')))` was checked as `h:3306`
but dialed `h:3307`, bypassing a port-pinning `remote_url_allow_hosts`
entry. Validate the effective port instead.

Co-Authored-By: Claude Fable 5 <[email protected]>
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 v25.12-must-backport v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants