Skip to content

Add a copy-returning maskURICredentials overload and use it instead of the local copies - #130533

Open
groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:mask-uri-credentials-copy-overload
Open

groeneai wants to merge 1 commit into
ClickHouse:masterfrom
groeneai:mask-uri-credentials-copy-overload

Conversation

@groeneai

@groeneai groeneai commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #126184
Related: #120407

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

Description

Follow-up to #126184 (comment): maskedURL in MetadataStorageFromIndexPages.cpp duplicated maskedURI in ReadWriteBufferFromHTTP.cpp.

src/Common/maskURIPassword.h gets [[nodiscard]] std::string maskURICredentials(std::string_view), the existing in-place masking applied to a copy. It replaces both helpers and five more places that copied a URL and masked the copy by hand: WriteBufferFromHTTP, HTTPException::makeExceptionMessage, StorageURL's getLastFilePath, HTTPConnectionPool and AvroConfluentSchemaRegistry. The last two called maskURIUserinfo and maskPresignedURLParameters directly, so they would have missed anything added to maskURICredentials later. Not converted, because they mask differently: S3 maskedURIString and RemoteHostFilter (they undo %3F between the two steps) and SettingsSecrets (it also hides values no URI parser can read and a wider userinfo).

A non-const std::string lvalue still resolves to the in-place bool overload, so the in-place callers are unchanged; const lvalues and rvalues get the copy. [[nodiscard]] makes a call that expects in-place masking of a const string a build error.

No behaviour change. 05212_http_uri_credentials_masked, 05404_http_error_body_presigned_credentials_scrubbed and 05315_avro_schema_registry_url_credentials_masked (50 randomized runs each) and the two test_storage_url index page tests pass. With the new overload changed to return its input unmasked, all of them and the new gtest case fail. The url() log and error text is identical to master.


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

…f the local copies

`maskURIPassword.h` only had the in-place `bool maskURICredentials(std::string &)`, so every caller that
needed a masked copy of a URL for a log line or an exception message (the raw string is still used for
the request, the schema cache key or `collectRequestCredentials`) wrote its own copy-then-mask:
`maskedURI` in ReadWriteBufferFromHTTP, `maskedURL` in MetadataStorageFromIndexPages (pointed out in
review of ClickHouse#126184), WriteBufferFromHTTP, HTTPException::makeExceptionMessage and
StorageURL's getLastFilePath. HTTPConnectionPool and AvroConfluentSchemaRegistry spelled out
`maskURIUserinfo` + `maskPresignedURLParameters` instead, so they would miss anything added to
`maskURICredentials` later.

Add `[[nodiscard]] std::string maskURICredentials(std::string_view)` and use it at all seven places.
A non-const `std::string` lvalue still binds the in-place overload (reference binding is an identity
conversion, the conversion to `std::string_view` is user-defined), so the existing in-place callers
are unchanged; const lvalues and rvalues get the copy. `[[nodiscard]]` turns a call that expects
in-place masking of a const string into a build error. A `std::string` by-value parameter would be
ambiguous with the in-place overload for every non-const lvalue, and a `Poco::URI` one would pull
Poco into the header and could not serve `maskedURL`.

Not converted because they mask differently: S3 `maskedURIString` and RemoteHostFilter (they undo
`%3F` between the two steps) and SettingsSecrets.

Behaviour-neutral: log and error text is identical to master.

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), plus my own cold review (1 nit).

# Sev Finding Verdict Evidence / action
1 💡 A non-const std::string lvalue still binds the in-place bool overload (src/Common/maskURIPassword.h:384) AGREE, not changed Every converted call passes an rvalue or a const lvalue (checked per site); the gtest case pins both bindings.

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-10:20261110-153900

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? N/A as a failure: behaviour-neutral refactor requested in review. The deterministic check is a mutation: making the new overload return its input unmasked turns MaskS3URLCredentials.MasksInPlaceOrIntoACopy, 05212_http_uri_credentials_masked, 05404_http_error_body_presigned_credentials_scrubbed, 05315_avro_schema_registry_url_credentials_masked and both test_storage_url index page tests red on every run.
b Root cause explained? maskURIPassword.h only had the in-place bool maskURICredentials(std::string &), so every caller needing a masked copy for a log line or an error wrote its own copy-then-mask, and two of them inlined the body.
c Fix matches root cause? Yes: one copy-returning overload next to the in-place one, used at all seven copies.
d Test intent preserved / new tests added? No existing test changed. One gtest case pins both overloads: a const string gets a masked copy and stays raw, a non-const string is masked in place and returns true.
e Both directions demonstrated? Real overload: gtest 8/8, the seven masking stateless tests 7/7, 05212/05404/05315 150/150 randomized runs, both integration tests pass. Mutated overload: all of those fail.
f Fix is general across code paths? All seven copy-then-mask sites with maskURICredentials semantics are converted. Different maskers are left as they are: S3 maskedURIString, RemoteHostFilter, SettingsSecrets.
g Fix generalizes across inputs (params/datatypes/wrappers)? Input is any URL string. Resolution checked per call site at compile time: all 18 converted calls bind the copy overload, all 6 in-place callers still bind the bool one.
h Backward compatible? (maintainer-approved exception only) Yes. No setting, format or protocol change; log and error text identical to master.
i Invariants and contracts preserved? The source URL stays raw where it is reused (request, schema cache key, collectRequestCredentials). The raw-URI HTTPException call sites in ReadWriteBufferFromHTTP are untouched.

Session id: cron:clickhouse-impl-slot-6:20261110-145800

@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a8c8fdf]

Summary: ✅


AI Review

Summary

PR #130533 adds a copy-returning maskURICredentials overload and replaces duplicated URL-masking helpers and call sites. Reviewed commit a8c8fdf258d01960f34b78d0bc3e1d6a6f34906f and all prior discussion. No actionable correctness, credential-redaction, or compatibility findings.

Missing context / blind spots
  • ⚠️ No local build or tests were run. The PR reports focused unit, functional, integration, and mutation-test results; broader CI was still running when checked.
Final Verdict

✅ Approve

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @CheSema, could you review this and add the can be tested label so CI runs? It adds a copy-returning maskURICredentials(std::string_view) overload to maskURIPassword.h and uses it at the seven places that copied a URL and masked the copy by hand (among them ReadWriteBufferFromHTTP, WriteBufferFromHTTP and HTTPConnectionPool), with no behaviour change.

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Nov 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing a8c8fdf25 with master 2170ef336 (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.

Slowest function optimization changes (ThinLTO)

Median per-function time ratio to the master baseline: programs/clickhouse ×0.93, programs/clickhouse-keeper ×1.07 (each binary is linked separately, on a different machine and with different build flags); deltas below are relative to it.

Binary Function Master PR Δ vs median
programs/clickhouse DB::registerFunctionConversion(DB::FunctionFactory&) 9.1 s 18.1 s +9.7 s (+114%)
Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Nov 19, 2026

This branch has not been deployed

No deployments
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-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant