Repository navigation
[SECURITY] Mask credentials embedded in HTTP URIs - #120407
Conversation
A password in an HTTP URI (`scheme://user:password@host`), as used by the `url` table function or an `HTTP` dictionary source, was disclosed in cleartext via exception messages, `SHOW CREATE DICTIONARY`, `system.query_log`, and the server log. Mask it at each site using `Common/maskURIPassword.h`, and add `05212_http_uri_credentials_masked`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Workflow [PR], commit [380c35e] Summary: ✅
AI ReviewSummaryThe PR masks HTTP URI credentials in read/write diagnostics, schema-inference errors, and the schema cache, and adds stateless coverage. ❌ Block: credential disclosure remains through sensitive query parameters, reflected presigned credentials, and token-only userinfo on other display surfaces. These findings already have inline threads; no duplicate comments were posted. The fixed schema-inference and reference-output threads were resolved. Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Complete the remaining credential-masking paths, strengthen the userinfo assertion, and run the focused stateless regression. |
Use `SYSTEM FLUSH LOGS query_log` instead of the global form, and filter `event_date >= yesterday()` instead of `today()` to avoid flakiness. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Two review findings on the credential-masking PR: 1. `ASTPair::formatImpl` masked the URI value of a dictionary source with `maskURIPassword`, which mishandles several cases: a query parameter containing `@` (e.g. `[email protected]`) was wrongly masked, a password that itself contains `@` leaked its tail, and a userinfo without a colon (`http://token@host`) was not masked at all. Switch to `maskURIUserinfo` (plus `maskPresignedURLParameters`), the same helpers S3 uses in `FunctionSecretArgumentsFinder`. The value is taken from the literal and re-emitted through an `ASTLiteral` so quoting and escaping are unchanged. 2. `ReadWriteBufferFromHTTP` only masked `getFileName`, while seven other sites still printed the credentialed URI. The reachable one is `assertResponseIsOk(current_uri.toString(), ...)`, which raises `Received error from remote server {}` on any non-2xx response - exactly what a wrong credential produces. Route every outward-facing URI string in the class through one `maskURICredentials` helper before logging or throwing. The regression test now also exercises an HTTP-status failure path (a request to an unknown path returns `404`), not only the CSV-parse suffix. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
| getUpdateFieldAndDate(uri); | ||
| LOG_TRACE(log, "loadUpdatedAll {}", uri.toString()); | ||
| std::string uri_for_logging = uri.toString(); | ||
| maskURIPassword(&uri_for_logging); |
There was a problem hiding this comment.
ReadWriteBufferFromHTTP and ASTPair::formatImpl now treat the whole URI userinfo plus presigned query parameters as credentials, but HTTPDictionarySource still only applies maskURIPassword here and in toString below. toString feeds both DictionaryFactory's Created dictionary source '{}' log and the system.dictionaries.source column, while loadUpdatedAll logs the updated URI directly, so SOURCE(HTTP(url 'https://bucket/x?X-Amz-Signature=SECRET' ...)) or http://token@host/x still leaks through those surfaces even after this PR.
Please route both sites through the same helper as ReadWriteBufferFromHTTP / ASTPair and add a focused regression for system.dictionaries.source or the reload log path.
Build profile diff (arm_release)Commit See the job log for details. |
| /// to the raw value and the result is re-emitted through a literal so that it is quoted and | ||
| /// escaped exactly as the original value would have been. | ||
| String masked = second->as<ASTLiteral>()->value.safeGet<String>(); | ||
| maskURIUserinfo(masked); |
There was a problem hiding this comment.
SHOW CREATE now uses maskURIUserinfo / maskPresignedURLParameters, but the system.query_log path is still on the old helper: FunctionSecretArgumentsFinder::findURLSecretArguments keeps calling maskURIPassword at src/Parsers/FunctionSecretArgumentsFinder.cpp:634,653.
That leaves the same cases from the earlier review exposed in query text. For example, url('http://user:pa@ss@host/p', ...) still records the trailing ss, url('http://token@host/p', ...) stays visible, and presigned URLs keep their signature. Please switch the url / urlCluster sanitizer to the same URI-credential helper used here and extend 05212_http_uri_credentials_masked with one system.query_log case that exercises it.
There was a problem hiding this comment.
three things still print credentials. one of them i missed in round 1 and only found now, and the reason is worth more than the fix, so it's inline below.
1. HTTPDictionarySource.cpp:145 and :248 — clickhouse-gh[bot]'s thread on this is correct; i verified both sites independently. :248 is toString, which feeds system.dictionaries.source — the surface this PR's description claims to fix.
2. src/IO/WriteBufferFromHTTP.cpp:49 — unchanged since round 1 (i re-posted this after my first submission dropped the review body, and that re-post never went out, so you may be seeing it for the first time):
LOG_TRACE((getLogger("WriteBufferToHTTP")), "Sending request to {}", uri.toString());full credentialed URL on every INSERT into a URL sink, success or failure.
3. src/Core/SettingsSecrets.h:28-32 — new to this round, and the one i missed before. maskURLCredentials still composes the weak masker:
bool masked = maskURIPassword(&value);
masked |= maskPresignedURLParameters(value);it is the masking function for format_avro_schema_registry_url, url_base and s3_base (SETTINGS_TO_HIDE, :42-46), so a password containing @ leaks its tail and a bare userinfo token isn't masked at all — through system.settings, query_log, session logs and settings profiles. the file's own comment shows the shape that changes: format_avro_schema_registry_url = 'http://user:[HIDDEN]@registry:8080'.
Switch HTTPDictionarySource, WriteBufferFromHTTP and CoreSettings::maskURLCredentials from maskURIPassword to maskURIUserinfo (plus maskPresignedURLParameters), so an '@' in the password or a bare userinfo token no longer leaks. Update test references. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Backport #120407 to 26.10: [SECURITY] Mask credentials embedded in HTTP URIs
…ror response ClickHouse#120407 scrubs the request's bearer token (`requestCredentialSecrets`) from the body of an HTTP error response, but `HTTPException::makeExceptionMessage` formatted the reason phrase raw. The reason phrase is remote content too, so a peer that answers `401 invalid token <token>` to a `url()` request carrying `headers('Authorization' = 'Bearer <token>')` put the token into the client error, the server log and `system.query_log.exception`. Apply the same scrub to the reason phrase, in the formatter that already holds the secrets and is reached by both callers that pass them. Rename the parameter `body_secrets` to `response_secrets`, since it no longer applies to the body only. The new test starts a local peer that reflects the token in its reason phrase: ClickHouse's own HTTP server never puts request content there, so no existing test reaches this path. Closes ClickHouse#125282 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The listing URLs built for a `url()` wildcard expanded from HTTP index pages
(and for a `web_index` disk) keep the source URL's userinfo, because the
index page request authenticates from it. The two `BAD_ARGUMENTS` errors
raised while listing ("redirected to a different origin" and "exceeds
max_http_index_page_size") formatted those URLs as is, so the password
reached the client, the server log and `system.query_log.exception`, while
the query text itself is logged masked. ClickHouse#120407 masked the URL renders of
the HTTP buffer layer; these messages are built above it.
Format a copy masked with `maskURICredentials`; the request and the origin
comparison keep the raw URLs.
Tests: the cross-origin redirect now points at a target with its own
userinfo, and the oversize test URL has userinfo. The assertions read the
server's part of the error, because the client appends the query text it
sent, which carries the credentials the test typed.
Closes ClickHouse#120425
Co-Authored-By: Claude Opus 5.5 <[email protected]>
S3 answers a presigned request whose signature does not match with a `SignatureDoesNotMatch` body that echoes the request's credentials outside URL form: `<AWSAccessKeyId>`, `<SignatureProvided>` (decoded), and `<CanonicalRequest>`, i.e. the query without the signature, with `&` escaped as `&`, carrying the raw `X-Amz-Credential` and `X-Amz-Security-Token`. `HTTPException::makeExceptionMessage` copies that body into the message, which reaches the client, `system.query_log` and the server log. ClickHouse#120407 masks the URI there and scrubs `body_secrets` from the body, but only `requestCredentialSecrets` fills that list, and it returns nothing but an `Authorization: Bearer` token. A presigned URL sends no such header, so the message printed `X-Amz-Signature=[HIDDEN]` in the URI and the same signature in the body. Running the URI masker over the body cannot replace this: it only rewrites `?name=value` / `&name=value`, misses element text, and matches nothing after `&` escaping. `makeExceptionMessage` now derives the presigned credentials from the `uri` it receives (`presignedURLCredentials`, next to the tolerant query decoder in `maskSensitiveQueryParameters`, renamed to `decodeQueryComponent`) and scrubs them together with `body_secrets`. Values are taken as sent and decoded, since S3 echoes both spellings; for `X-Amz-Credential` only the key id before the first `/` is a secret. The combined list is sorted longest first, so a secret contained in a longer one cannot break the longer one's match. The work runs only when an exception is built, and it covers every `HTTPException`, including direct constructions. URL metadata such as `X-Amz-Date` or `Expires` is not scrubbed: its short values would be replaced throughout the body. This relies on `uri` arriving unmasked. `ReadWriteBufferFromHTTP::callImpl` was the one remote-body caller passing `maskedURI(current_uri)`; it now passes `current_uri.toString()`, and the printed URI is unchanged because `makeExceptionMessage` applies the same `maskURICredentials` to it. GCS names (`X-Goog-*`, `GoogleAccessId`) are not included: the echo is known for S3 only, and a GCS V4 identifier is a percent-encoded e-mail whose raw and decoded spellings differ. The test answers like S3 from a local endpoint: SigV4 `SELECT` and `INSERT`, SigV2, and a signature that is a prefix of the session token. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #120407 onto 26.3. This branch still has the std::istream HTTP client API, so body_secrets and requestCredentialSecrets go through its receiveResponse / assertResponseIsOk signatures, the masked LOG_TRACE goes into the WriteBufferFromHTTP constructor (no WriteBufferFromHTTPRequestSender), and the master-only cancellation exit in doWithRetries is not taken. StorageURL.cpp gets the maskURIPassword.h include. maskURIPassword.h has no maskURIUserinfo / findURIAuthority here, so maskURICredentials uses the userinfo regular expression and the schema cache table a local startsWithURIScheme check. 05212 drops the bearer-token reflection case: it relies on URL parameter credentials taking precedence over the Authorization header (#108980), which this branch does not have. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #120407 onto 26.7. This branch still has the std::istream HTTP client API, so body_secrets and requestCredentialSecrets go through its receiveResponse / assertResponseIsOk signatures, the masked LOG_TRACE goes into the WriteBufferFromHTTP constructor (no WriteBufferFromHTTPRequestSender), and the master-only cancellation exit in doWithRetries is not taken. StorageURL.cpp gets the maskURIPassword.h include. maskURIPassword.h has no maskURIUserinfo / findURIAuthority here, so maskURICredentials uses the userinfo regular expression and the schema cache table a local startsWithURIScheme check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #120407 onto 26.8. This branch still has the std::istream HTTP client API, so body_secrets and requestCredentialSecrets go through its receiveResponse / assertResponseIsOk signatures, the masked LOG_TRACE goes into the WriteBufferFromHTTP constructor (no WriteBufferFromHTTPRequestSender), and the master-only cancellation exit in doWithRetries is not taken. StorageURL.cpp gets the maskURIPassword.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cherry-pick of #120407 onto 26.9. This branch still has the std::istream HTTP client API, so body_secrets and requestCredentialSecrets go through its receiveResponse / assertResponseIsOk signatures, the masked LOG_TRACE goes into the WriteBufferFromHTTP constructor (no WriteBufferFromHTTPRequestSender), and the master-only cancellation exit in doWithRetries is not taken. StorageURL.cpp gets the maskURIPassword.h include. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The show_create and system.query_log checks test that the url of an HTTP dictionary source is masked in the dictionary definition. On master that comes from #123364, which is not in 26.3, so both checks fail here. The runtime paths changed by #120407 stay covered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The show_create and system.query_log checks test that the url of an HTTP dictionary source is masked in the dictionary definition. On master that comes from #123364, which is not in 26.3, so both checks fail here. The runtime paths changed by #120407 stay covered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The show_create and system.query_log checks test that the url of an HTTP dictionary source is masked in the dictionary definition. On master that comes from #123364, which is not in 26.3, so both checks fail here. The runtime paths changed by #120407 stay covered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #120407 to 26.8: [SECURITY] Mask credentials embedded in HTTP URIs
Backport #120407 to 26.3: [SECURITY] Mask credentials embedded in HTTP URIs
Backport #120407 to 26.7: [SECURITY] Mask credentials embedded in HTTP URIs
The show_create and system.query_log checks test that the url of an HTTP dictionary source is masked in the dictionary definition. On master that comes from #123364, which is not in 26.3, so both checks fail here. The runtime paths changed by #120407 stay covered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Backport #120407 to 26.9: [SECURITY] Mask credentials embedded in HTTP URIs
…ning
`TaskTracker::waitForTaskTerminal` polls a cancelled remote task with
`getTaskStatus(..., for_cleanup = true)`, whose receive timeout is
deliberately short (wait_for_ms + 2000 ms) and which does not retry, so a
slow worker is expected to exceed it. Its `catch (...)` logged that
`Poco::TimeoutException` at Error, while the caller reports the same
outcome ("did not reach a terminal state after cancellation; leaving it
for the worker to reclaim") at Warning.
When the teardown runs on the thread of a `KILL QUERY ... SYNC` query, the
line is streamed to that client. `04335_distributed_plan_cancel` keeps
only Error and above on its clients (ClickHouse#119101), so the Error reached its
stderr and the runner failed it on master (amd_msan; one status poll was
answered after 4.5 s at the job's load peak):
https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?REF=master&sha=6ab09677220b44315d06eb9c46c673b80d571660&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_msan%2C%20parallel%2C%203%2F3%29
Log a timeout of the cleanup poll at Warning. Every other exception stays
at Error: the same catch surfaced a broken interserver credential
("No authentication information found") in ClickHouse#120407.
Validated with temporary worker mutations that are not part of this commit:
- a 3 s delay on status polls of cancelled tasks: without the fix 10/10
runner FAIL `having stderror` with the Error `Timeout` line; with the
fix 10/10 OK, the timeout logged at Warning (3 rows per run), 0 at Error.
- a non-timeout failure injected instead, with the fix: 5/5 FAIL, logged
at Error.
- no mutation, with the fix: 20/20 OK without randomized settings, 50/50
OK with them, and 8 remote-execution distributed-plan tests OK.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A password in an HTTP URI (
scheme://user:password@host), as used by theurltable function or anHTTPdictionary source, was disclosed in cleartext via exception messages,SHOW CREATE DICTIONARY,system.query_log, and the server log. Mask it at each site usingCommon/maskURIPassword.h, and add05212_http_uri_credentials_masked.fix https://github.com/ClickHouse/clickhouse-private/issues/69243
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Mask credentials embedded in HTTP URIs
Workflow [PR]
Sync PR [sync-upstream/pr/120407]
Version info
26.11.1.15-master(included in26.11and later)26.10.2.5,26.9.24.5,26.8.32.17,26.7.36.6,26.3.58.4