Skip to content

Mask the connection string in ODBC/JDBC bridge request URLs - #126223

Closed
groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:mask-xdbc-connection-string
Closed

groeneai wants to merge 8 commits into
ClickHouse:masterfrom
groeneai:mask-xdbc-connection-string

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #120407
Related: #106442

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

The connection string of the odbc and jdbc table functions and of the ODBC and JDBC table engines, password included, is no longer shown in cleartext in the bridge request URL quoted by errors, system.query_log, the server log and system.schema_inference_cache. The query itself already showed it as [HIDDEN].

Description

On 26.8.28.14-lts, and on master after #120407, a failed bridge request quotes its URL with the password while the logged query shows odbc('[HIDDEN]', 'db', 't'):

SELECT * FROM odbc('DSN=nonexistent_dsn;PWD=SEKRIT_ODBC_p0', 'db', 't')
Code: 86. DB::HTTPException: Received error from remote server http://127.0.0.1:60245/columns_info?use_connection_pooling=1&version=1&connection_string=DSN%3Dnonexistent_dsn%3BPWD%3DSEKRIT_ODBC_p0&schema=db&table=t&...

The same URL reaches system.query_log.exception, the server log, system.schema_inference_cache.source after a successful read, and the remote_url_allow_hosts rejection. With a named collection, a user who cannot read system.named_collections gets its password this way.

The server sends the connection string to the bridge as the connection_string query parameter, and maskURICredentials, which all these renders call since #120407, masks only the userinfo and the presigned-URL parameters.

maskPresignedURLParameters, which maskURICredentials and RemoteHostFilter::checkURL call, now also hides the whole value of connection_string: its grammar belongs to the driver, so the password cannot be located inside it. Its other callers hide it too (for example, url('http://h/?connection_string=...') in the logged query text). The bridge protocol does not change, so older external bridges keep working.

05404_xdbc_connection_string_masked checks the client error, system.query_log and an ODBC engine insert, and a new test_allowed_url_from_config case checks the URL rejection; both fail without the change. The test uses a DSN that does not exist, because a read that really connects crashes the external bridge when the flaky check runs the test in parallel; the success path (system.schema_inference_cache) was checked locally against the CI bridge.


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

A bridge request carries the whole ODBC/JDBC connection string, password
included, in the `connection_string` query parameter of its URI. The query
text masks it as '[HIDDEN]', but the URI was shown as is wherever it is
rendered: in the error of a failed bridge request (client, query_log,
system.errors, server log), in the ReadWriteBufferFromHTTP/WriteBufferFromHTTP
log lines, in system.schema_inference_cache.source after a successful read,
and in the remote_url_allow_hosts rejection. With a named collection this
discloses a password the user cannot read in system.named_collections.

All of these sinks render through maskURICredentials, which knew only the
userinfo and the presigned-URL parameters. Add the third carrier there:
maskXDBCConnectionStringParameter hides the whole value, because its grammar
belongs to the driver. RemoteHostFilter::checkURL composes the maskers by
hand, so it calls it too. The parameter-value scan of
maskPresignedURLParameters moves unchanged into a template shared by both,
and the parameter name becomes a constant of the bridge protocol, used both
where it is sent and where it is masked.

Masking at render time, not changing the protocol (sending the string in the
request body), keeps version-skewed external bridges working, and it is the
only layer that reaches system.schema_inference_cache, whose key must keep
the connection string.

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

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex): 0 findings.

Session id: cron:clickhouse-review-self-slot-58:20261016-061700

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. SELECT * FROM odbc('DSN=no_such_dsn;PWD=<secret>', 'db', 't') against the CI bridge 25.1.5.31 prints the password on every run on master 26.11.1.16 (46932ee3b051, contains #120407); the same leak on 26.8.28.14-lts with a bridge answering 500.
b Root cause explained? Yes. The connection string goes to the bridge as the connection_string query parameter; maskURICredentials (and RemoteHostFilter::checkURL) masked only the userinfo and the presigned-URL parameters.
c Fix matches root cause? Yes. The shared masking policy gains the missing carrier (whole value), so every render that calls it is fixed at once, system.schema_inference_cache included.
d Test intent preserved / new tests added? Yes. New 05404_xdbc_connection_string_masked and a new test_allowed_url_from_config case; the gtest RE2 equivalence for maskPresignedURLParameters passes 6/6.
e Both directions demonstrated? Yes. CI stateless image: master FAIL (3x cleartext), fix OK, also with async inserts and a Replicated database. Integration case: master fails only the new case, fix 5/5.
f Fix is general across code paths? Yes. All four senders use one protocol constant; all renders were enumerated (HTTP exception, HTTP buffer logs, schema cache, RemoteHostFilter).
g Fix generalizes across inputs (params/datatypes/wrappers)? Yes. odbc, jdbc, ODBC engine read and insert, named collection, async insert, Replicated database; value ending at & and at the end of the URL. Type wrappers: N/A.
h Backward compatible? (maintainer-approved exception only) Yes. Diagnostic text only; bridge protocol unchanged; no setting. A user url() with a connection_string parameter is now also shown as [HIDDEN] (intended).
i Invariants and contracts preserved? Yes. maskPresignedURLParameters behaves as before (gtest RE2 equivalence), one-pass construction kept. Flaky-check shape: 100/100 (--test-runs 50 -j 16 x 2), 0 bridge crashes.

Session id: cron:clickhouse-impl-self-slot-57:20261016-060000

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [376951a]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

PR #126223 masks the entire connection_string parameter when rendering ODBC/JDBC bridge request URLs, preserving the bridge protocol. Reviewed head 376951a34194715a87f9ec145c2e320b694657f2, the current code, and all prior discussion. No actionable findings.

Missing context / blind spots
  • ⚠️ Current-head regression CI is still pending; no local ClickHouse build is available. The earlier head 6d728dc712e0 passed both 05404_xdbc_connection_string_masked and test_rejected_url_credentials_masked[xdbc_connection_string] in the CI reports. Completed current-head functional and integration runs would close this validation gap.
Final Verdict

Status: ✅ Approve. No review changes required; normal CI checks still apply.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @GrigoryPervakov @hanfei1991, could you review this? The ODBC/JDBC bridge request URL carries the connection string, password included, as the connection_string query parameter, and maskURICredentials (from #120407) did not mask it, so errors, system.query_log and the server log printed it in cleartext; this masks its whole value.

@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). label Oct 16, 2026
@hanfei1991 hanfei1991 self-assigned this Oct 16, 2026
Comment thread src/Common/BridgeProtocolVersion.h Resolved
Comment thread src/Common/maskURIPassword.h Outdated
/// The whole connection string a bridge request carries is hidden: its grammar belongs to the ODBC or JDBC driver.
inline bool maskXDBCConnectionStringParameter(std::string & url)
{
return maskURIQueryParameterValues(url, [](std::string_view name) { return name == XDBC_BRIDGE_CONNECTION_STRING_PARAMETER; });

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.

Do we actually need new function maskXDBCConnectionStringParameter and maskURIQueryParameterValues?
Looks like we can add a check name == "connection_string" in is_secret_parameter

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 2037d12: both functions are removed, and is_secret_parameter checks name == "connection_string". This also covers the other callers of maskPresignedURLParameters: for example, url('http://h/?connection_string=x') is now logged as connection_string=[HIDDEN] (checked locally). The tests are unchanged and pass (05404 50/50 in the CI image, test_allowed_url_from_config 5/5).

Per review: instead of a separate masker and a bridge-protocol constant,
treat `connection_string` as one more secret parameter name in
`maskPresignedURLParameters`. `maskURICredentials` and
`RemoteHostFilter::checkURL` already call it, so every render of a bridge
request URL is covered, and the other callers (e.g. the `url()` argument
masking of the query text) hide the parameter too.

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

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 2037d12

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Build (arm_tidy, 3/4) / Build ClickHouse master build break, not from this PR (it does not touch the file): unit_tests_dbms does not compile, gtest_functions_stress.cpp:2367: error: value of type 'const ResolvedAddress' is not contextually convertible to 'bool'; this run built master from before the fix #126269 (external, merged)
Finish Workflow / Post Hooks new_tests_check.py: the Bugfix validation jobs were dropped by the build failure above #126269 (the owner of the first row)
CH Inc sync - CH Inc sync (private, not actionable by me)
Mergeable Check, PR praktika rollups of the rows above #126269 (the owner of the first row)

The build failure dropped 92 dependent jobs, so no functional test has run on this head yet.

Session id: cron:our-pr-ci-monitor:20261016-150006

@hanfei1991

Copy link
Copy Markdown
Member

clang tidy failed:

[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2367:13: error: value of type 'const ResolvedAddress' is not contextually convertible to 'bool' [clang-diagnostic-error]
[2026-10-16 14:39:02]  2367 |         if (resolved && resolved->kind == StackTrace::AddressKind::OtherObject)
[2026-10-16 14:39:02]       |             ^~~~~~~~
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2367:22: error: invalid operands to binary expression ('const ResolvedAddress' and 'bool') [clang-diagnostic-error]
[2026-10-16 14:39:02]  2367 |         if (resolved && resolved->kind == StackTrace::AddressKind::OtherObject)
[2026-10-16 14:39:02]       |             ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2367:33: error: member reference type 'const ResolvedAddress' is not a pointer; did you mean to use '.'? [clang-diagnostic-error]
[2026-10-16 14:39:02]  2367 |         if (resolved && resolved->kind == StackTrace::AddressKind::OtherObject)
[2026-10-16 14:39:02]       |                         ~~~~~~~~^~
[2026-10-16 14:39:02]       |                                 .
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2368:52: error: member reference type 'const ResolvedAddress' is not a pointer; did you mean to use '.'? [clang-diagnostic-error]
[2026-10-16 14:39:02]  2368 |             suffix = fmt::format(" in {}", resolved->object);
[2026-10-16 14:39:02]       |                                            ~~~~~~~~^~
[2026-10-16 14:39:02]       |                                                    .
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2369:18: error: value of type 'const ResolvedAddress' is not contextually convertible to 'bool' [clang-diagnostic-error]
[2026-10-16 14:39:02]  2369 |         else if (resolved && resolved->kind == StackTrace::AddressKind::UnknownMapping)
[2026-10-16 14:39:02]       |                  ^~~~~~~~
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2369:27: error: invalid operands to binary expression ('const ResolvedAddress' and 'bool') [clang-diagnostic-error]
[2026-10-16 14:39:02]  2369 |         else if (resolved && resolved->kind == StackTrace::AddressKind::UnknownMapping)
[2026-10-16 14:39:02]       |                  ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2369:38: error: member reference type 'const ResolvedAddress' is not a pointer; did you mean to use '.'? [clang-diagnostic-error]
[2026-10-16 14:39:02]  2369 |         else if (resolved && resolved->kind == StackTrace::AddressKind::UnknownMapping)
[2026-10-16 14:39:02]       |                              ~~~~~~~~^~
[2026-10-16 14:39:02]       |                                      .
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2371:48: error: value of type 'const ResolvedAddress' is not contextually convertible to 'bool' [clang-diagnostic-error]
[2026-10-16 14:39:02]  2371 |         res += fmt::format("\n{}. {}{} {}", i, resolved ? resolved->address : frame, suffix, symbol ? demangle(symbol->name) : "?");
[2026-10-16 14:39:02]       |                                                ^~~~~~~~
[2026-10-16 14:39:02] /ClickHouse/src/Functions/tests/gtest_functions_stress.cpp:2371:67: error: member reference type 'const ResolvedAddress' is not a pointer; did you mean to use '.'? [clang-diagnostic-error]
[2026-10-16 14:39:02]  2371 |         res += fmt::format("\n{}. {}{} {}", i, resolved ? resolved->address : frame, suffix, symbol ? demangle(symbol->name) : "?");
[2026-10-16 14:39:02]       |                                                           ~~~~~~~~^~

Please try to fix it in another PR if it is not urelate. and merge master if it is fixed

@groeneai

Copy link
Copy Markdown
Collaborator Author

Unrelated to this PR (gtest_functions_stress.cpp is not in the diff): it was a master build break, already fixed by #126269. I merged master in d3a9fad, which includes that fix; the PR diff is unchanged.

@clickhouse-gh

clickhouse-gh Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 6d728dc71 with master 8b93f69fa (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

34 translation units recompiled, 179 s compile time in total, 31 of them have a recent master baseline.

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

Job report

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - d3a9fad

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values master regression from my merged #124131 (semantic conflict with the test added by #124507), not from this PR: line 4 prints 0 instead of 1 on every true-master run from d64fd503b42e to aa90758f1888; this run built master from before the revert #126396 (external, merged)
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
Stateless tests (arm_asan_ubsan, azure, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
Stateless tests (arm_binary, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
Stateless tests (arm_binary, AsyncInsert, s3 storage, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
Stateless tests (arm_binary, ParallelReplicas, s3 storage, parallel) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
Stateless tests (arm_binary, s3 storage, DBReplicated, parallel, 2/2) / 05339_string_filters_during_scan_parquet_short_dictionary_values same master failure #126396 (the owner of the first row)
CH Inc sync - CH Inc sync (private, not actionable by me)
Mergeable Check, PR praktika rollups of the rows above #126396 (the owner of the first row)

#126396 reverts #124131; the first master commit after it (0a3052562045) passes the test. The NOT_FAILED rows in the AsyncInsert and ParallelReplicas jobs (00952, 02912, 03008 x2, 01414, 02884) are tests that passed while still listed in a blacklist; they are not failures. CIDB has no other FAIL or ERROR row on this head.

Session id: cron:our-pr-ci-monitor:20261017-040005

@hanfei1991

Copy link
Copy Markdown
Member

@groeneai check the CI failure

@groeneai

Copy link
Copy Markdown
Collaborator Author

All 7 failures were 05339_string_filters_during_scan_parquet_short_dictionary_values, a master regression unrelated to this PR, fixed on master by #126396. I merged master (906bea99e08a, which contains it) in 0b862a7; CI is re-running.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Fixing PR for the Upgrade check (amd_release) "Cannot check whether the row policies can be applied" red on 46829b6: #126895. The failure is a table without files (Code 107), not this PR.

qiuyanjun888 pushed a commit to qiuyanjun888/ClickHouse that referenced this pull request Oct 22, 2026
…hout it

The stress phase can leave a database-level policy (`ON test_1.* USING 1`,
from an interrupted 02703) over a database where another test left a data
lake table without files (04894 deletes them in an `EXIT` trap). The
row-policy check stopped on that table with `Code: 107 FILE_DOESNT_EXIST`,
which is not a filter error, and wrote a false `Cannot check whether the row
policies can be applied` FAIL row (seen on ClickHouse#126223).

The batched check of all covered tables stays the fast path. When it fails
with an analysis error or 107, the tables are checked one by one, with and
without the filter: a table that fails the same way without the filter is
logged to `unreadable_row_policy_tables.txt` and skipped, a filter that fails
on a readable table is classified as before, anything else is a FAIL row.
A `DeltaLakeLocal` table without files fails with `Code: 742
DELTA_KERNEL_ERROR` instead of 107 and is handled the same way.

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

Copy link
Copy Markdown
Member

@groeneai check the CI please, if not our fault, please merge master

…c-connection-string

# Conflicts:
#	src/Common/maskURIPassword.h
#	tests/integration/test_allowed_url_from_config/test.py
@groeneai

groeneai commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

The red was Bugfix validation (functional tests, *): the server did not start (exit 36 on the SLRU max_file_segment_size check) because the re-run paired the master-HEAD binary with this PR's older merge commit, so the test never ran. It is not caused by this PR; #127524 fixed that in the harness.

I merged master (4ce8938) in 376951a, which also resolves the conflict in maskURIPassword.h: the connection_string check is now in master's new is_secret_parameter (name == "sig" || name == "connection_string" || isPresignedURLParameterName(name)).

@hanfei1991

Copy link
Copy Markdown
Member

Most problems in this PR has been fixed, let's close it

@hanfei1991 hanfei1991 closed this Nov 9, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

Measured on today's master (41a73de, debug build): the connection_string leak this PR fixes is still there. With a bridge that answers 500, which the real bridge does when the ODBC connect fails:

SELECT * FROM odbc('DSN=nonexistent_dsn;PWD=SEKRIT_ODBC_p0', 'db', 't')
Code: 86. DB::HTTPException: Received error from remote server http://127.0.0.1:60245/columns_info?use_connection_pooling=1&version=1&connection_string=DSN%3Dnonexistent_dsn%3BPWD%3DSEKRIT_ODBC_p0&schema=db&table=t&external_table_functions_use_nulls=1. HTTP status code: 500 ...

The same cleartext password goes to system.query_log.exception (where the query text is masked as odbc('[HIDDEN]', ...)) and to the server log, for jdbc(), ENGINE = ODBC reads and inserts too. With odbc(nc) a user who is denied SELECT ON system.named_collections gets the collection's password back in the error.

My previous comment was ambiguous, sorry: the connection_string check exists only in this PR's branch. Master's is_secret_parameter is still name == "sig" || isPresignedURLParameterName(name).

@hanfei1991 should I reopen this PR as it is (the name == "connection_string" check plus the two tests), or do you prefer a different fix?

@hanfei1991

Copy link
Copy Markdown
Member

@groeneai we can open an another PR only fixing name == "connection_string"

@groeneai

Copy link
Copy Markdown
Collaborator Author

Acknowledged. I'll open a new PR whose code change is only the name == "connection_string" check in is_secret_parameter, with its regression test, and link it here.

@groeneai

Copy link
Copy Markdown
Collaborator Author

Opened #130576: its only code change is the name == "connection_string" check in is_secret_parameter, with the regression test 05617_xdbc_connection_string_masked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-foreign-db Connectivity to external databases (ODBC/JDBC, MySQL, PostgreSQL, etc.). pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants