Repository navigation
Cherry pick #120407 to 26.9: [SECURITY] Mask credentials embedded in HTTP URIs - #126164
Merged
Merged
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]>
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]>
…fix-http-uri-credential-leak
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]>
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]>
…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
Co-authored-by: Shaohua Wang <[email protected]>
Co-authored-by: Shaohua Wang <[email protected]>
[SECURITY] Mask credentials embedded in HTTP URIs
Contributor
Author
|
Dear @tiandiwonder, @hanfei1991, this cherry-pick PR has not been updated for 3d0h6m59s. 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-picklocally.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:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job