Skip to content

Cherry pick #120407 to 26.7: [SECURITY] Mask credentials embedded in HTTP URIs - #126162

Merged
PedroTadim merged 40 commits into
backport/26.7/120407from
cherrypick/26.7/120407
Oct 19, 2026
Merged

PedroTadim merged 40 commits into
backport/26.7/120407from
cherrypick/26.7/120407

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #120407

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

hanfei1991 and others added 30 commits September 16, 2026 15:28
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]>
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]>
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]>
Add maskURICredentials (userinfo + presigned parameters) to Common/maskURIPassword.h
and use it everywhere instead of the three duplicate wrappers and the inline
maskURIUserinfo + maskPresignedURLParameters pairs.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
HTTPException::makeExceptionMessage embedded the request URI and the remote
response body verbatim, so a presigned-URL signature reflected in a 404 body
reached system.query_log.exception. Mask both in the single choke point, which
also covers callers that pass a raw request URI.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace assert_masked with assert_shape, which requires the exact masked form
(scheme://[HIDDEN]@host, or X-Amz-Signature=[HIDDEN]) so a text that never carried
the credential can no longer pass. Add an INSERT INTO url() case - the only one
reaching WriteBufferFromHTTP - with a presigned URL and a missing ?database whose
404 body does not echo the URI.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
StorageSystemSchemaInferenceCache inserted the cache key source verbatim, so a
credentialed url()/S3 URL that got its schema inferred exposed the userinfo (and
presigned parameters) in system.schema_inference_cache.source. Mask it at display
with maskURICredentials, leaving the real cache key untouched. Cover it in 05212.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
An HTTP error response body can reflect the request's own credentials in any form
- e.g. a 403 auth error echoing the user name parsed from the URL userinfo - which
no pattern masker can catch. When the request carried credentials (an Authorization
header), replace the reflected body with [HIDDEN] in the exception instead of logging
it; otherwise keep masking only the presigned-URL parameters a reflected request URL
can carry. Fixes the intermittent cleartext leak into system.query_log.exception.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the whole-body masking (which hid useful non-credential errors such as
"the token is expired") with scrubbing the exact credential strings the request
carried: an error body can echo them back verbatim (e.g. a 403 naming the user).
requestCredentialSecrets decodes the Basic user name/password or the Bearer token
from the Authorization header; makeExceptionMessage removes those from the body and
keeps the rest. Restores the REST-catalog diagnostic while still masking the leak.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The cpp style check forbids a literal std::vector in src/IO; use the standard
Strings alias (already used elsewhere in src/IO) for the credential-secrets list.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Shaohua Wang <[email protected]>
The master merge of `mongodb-connection-options-secrets` narrowed the URI
masking branch in `ASTPair::formatImpl` from `isURIKey` (both `url` and `uri`)
to `uri`/`options` only, and swapped `maskURICredentials` for
`maskMongoDBConnectionString`. As a result the `HTTP` dictionary source `url`
matched no masking branch and its userinfo credentials leaked in cleartext in
`SHOW CREATE DICTIONARY` and in the query text stored in `system.query_log`,
even though `hasSecretParts` still reported the pair as secret.

Unify the branch so an `HTTP` source `url` is masked with `maskURICredentials`
(whole userinfo plus presigned-URL parameters) while a MongoDB `uri`/`options`
keeps `maskMongoDBConnectionString`. Fixes `show_create` and the dictionary
query_log rows in `05212_http_uri_credentials_masked`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Shaohua Wang <[email protected]>
Co-authored-by: Shaohua Wang <[email protected]>
hanfei1991 and others added 10 commits October 12, 2026 15:23
…tial-leak

# Conflicts:
#	src/Dictionaries/HTTPDictionarySource.cpp
#	src/Parsers/ASTFunctionWithKeyValueArguments.cpp
#	src/Parsers/FunctionSecretArgumentsFinder.cpp
#	tests/integration/test_mask_sensitive_info/test.py
Master's merge replaced the branch's URL credential masking with its
`SecretArguments` registry, whose query-text sanitizer masks the userinfo
password only (`scheme://user:[HIDDEN]@host`), not the whole userinfo. Drop the
section that asserted whole-userinfo masking of the query text in
`system.query_log` for a password containing `@` and for a bare userinfo token -
those shapes are not masked whole by master's sanitizer.

The remaining checks still cover the features unique to this branch, which
master does not test: the masked URI in the HTTP error exception, the scrubbed
HTTP error response body, `system.schema_inference_cache.source`, and that a
`Basic` `Authorization` header is neither decoded (so a malformed one cannot
turn a successful request into an error) nor over-masked.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…tial-leak

# Conflicts:
#	src/IO/HTTPCommon.cpp
#	src/IO/HTTPCommon.h
#	src/IO/ReadWriteBufferFromHTTP.cpp
[SECURITY] Mask credentials embedded in HTTP URIs
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default labels Oct 16, 2026
@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor Author

Dear @tiandiwonder, @hanfei1991, this cherry-pick PR has not been updated for 3d0h8m12s. Please resolve the conflicts to backport #120407, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity.

@PedroTadim
PedroTadim merged commit 69ccbe6 into backport/26.7/120407 Oct 19, 2026
176 of 187 checks passed
@PedroTadim
PedroTadim deleted the cherrypick/26.7/120407 branch October 19, 2026 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-bugfix Pull request with bugfix, not backported by default pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants