Repository navigation
Hide the Azure SAS signature and the lower-case SigV2 session token in masked URLs - #121348
Algunenano merged 17 commits into
Conversation
maskPresignedURLParameters is the only thing that hides a credential carried
in a URL's query string, and its name set comes entirely from AWS SigV2/SigV4
and the Google signer. Azure puts its credential in the query string just like
a presigned S3 URL does: parseAzureURL moves an Azure URL's query verbatim onto
the account URL precisely because AzureBlobStorage::processURL recovers the SAS
from there. So sig, the HMAC of a shared access signature, reached
system.query_log.query, formatted_query, Settings[...], system.settings,
system.processes and settings profiles in cleartext, while the AWS parameter
beside it in the same string was hidden:
before: s3('https://b/f.csv?X-Amz-Signature=[HIDDEN]&sig=CANARY', 'CSV')
after: s3('https://b/f.csv?X-Amz-Signature=[HIDDEN]&sig=[HIDDEN]', 'CSV')
sig becomes a fifth exact, case-sensitive entry of exact_names, which serves
both callers of the helper (the s3-family url argument, and the url_base /
s3_base / format_avro_schema_registry_url setting values).
Designs considered and rejected, so they are not re-proposed:
* Adding sig to BackupInfo::removeCredentialsFromS3URL as well. That function
REMOVES parameters from a backup locator that has to stay openable on
restore, rather than masking a printed one, so adding a name there is a
functional change with a breakage mode. It is also unreachable for Azure:
withoutS3Credentials returns early for every engine but S3. The three
comments that claimed the two sets mirror each other are corrected instead.
* Matching case-insensitively. Azure emits the lowercase spelling, so ?SIG=
cannot be constructed as a working credential and was never reproduced;
the case-sensitivity is pinned by test arms instead of coded around.
* Matching sig as a prefix or substring. It would hide ?design=, ?signed= and
?sign=. maskSensitiveQueryParameters.cpp already spells out this trap for
the same name on the HTTP handler path.
* Reusing isSensitiveParameterName from maskSensitiveQueryParameters.cpp. It
is substring-based over {secret, password, token, credential, signature,
key}, so it would newly hide ?AWSAccessKeyId= and any ?...key...= in every
s3 URL, and it would destroy the re2-equivalence property the gtest holds.
* Adding sig to S3::URI's presigned detection. That set decides whether a '?'
opens a presigned query or a key wildcard, so changing it changes URL
parsing rather than logging.
Known residuals: ?SIG= and ?%73ig= stay visible. The percent-encoding
asymmetry already holds for every name in the set, because the scan does not
decode.
The dictionary HTTP source and azureBlobStorage's storage_account_url form run
no presigned masker at all, so they leak X-Amz-Signature too. Those are missing
callers rather than a missing name.
The gtest's re2 reference pattern gains the name in the same commit, so the
equivalence test keeps covering it, and sig / SIG / design join the random
differential's token list.
Related: ClickHouse#121257
Co-Authored-By: Claude Opus 5 <[email protected]>
The previous commit added sig to the name set but compared the RAW bytes of a query parameter's name, and the storage endpoint decodes those bytes before it authenticates. The two therefore disagreed about what the parameter is called, so a fully working shared access signature could be delivered under a name the masker did not recognise and its signature was still printed in cleartext. Measured against Azurite 3.35 with one valid SAS, varying nothing but the spelling of the name: sig 200 sas-ok %73ig 200 sas-ok SIG 403 AuthFailure s%69g 200 sas-ok Sig 403 AuthFailure %73%69%67 200 sas-ok %53IG 403 AuthFailure This supersedes the previous commit's "?SIG= and ?%73ig= stay visible" note. Both halves of that table are now load-bearing: * The encoded lowercase spellings authenticate, so they are credentials and are hidden. isPresignedURLSecretParameterName tests the raw name first and, only when that fails and the name contains a '%', builds a single-pass decoded copy and tests that too. The decode is one pass because the endpoint's is one pass, so a twice-encoded ?%2573ig= is not sig here and is not a credential there. * The case variants do NOT authenticate, so ?SIG=, ?Sig= and ?%53IG= stay readable. That is the only remaining residual, and it is now a measurement rather than an assumption: the earlier commit rejected case-insensitivity as unmeasured hardening, and the 403s confirm the ruling. Only percent escapes are decoded. maskSensitiveQueryParameters also maps '+' to a space because HTMLForm::readQuery does, but that is ClickHouse's own HTTP handler, not the Azure client, and ?s+ig= was never measured to authenticate. That difference from the sibling is named in the code. A name with no '%' allocates nothing: the guard precedes the only std::string in the function. Removing it costs 24% on a URL with 21 percent-free parameters (200k iterations, -O2, 211 ms against 262 ms). Of the four classifiers that answer this question, this was the only one that could have the defect, because it is the only one that scans the string itself instead of reading names through a URI parser: maskSensitiveQueryParameters decodes its own names, while BackupInfo::removeCredentialsFromS3URL and S3::URI both take theirs from Poco::URI::getQueryParameters(), which decodes each name before returning it (base/poco/Foundation/src/URI.cpp:385). Neither is changed. The name-set test moved verbatim out of the lambda into matchesPresignedURLCredentialName so that the decoded name can be tested with the same predicate and no lambda is nested inside another. No caller changes. Tests: the re2 differential cannot decode, so its presigned leg is narrowed to names with no percent escape and given a presigned_comparisons == url_corpus.size() assertion, which keeps the narrowing from hollowing it out (all 46 corpus inputs are still compared, none carries a '%'). The encoded behaviour gets its own absolute-oracle table covering partial, full, double, malformed, truncated, uppercase-decoding and '+' spellings, and the prefix family as well as the exact family. 05056_settings_secret_masking gains one appended end-to-end arm. Related: ClickHouse#121257 Co-Authored-By: Claude Opus 5 <[email protected]>
Delete the two lead-ins and the two rationale lines that narrate the new code (the <cctype> note repeats the one this header already carries at :88-89 with its reason); compress the decode property to three lines and the sibling-set note to one; drop the two now-tautological pointers to maskPresignedURLParameters in FunctionSecretArgumentsFinder.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings across 2 passes;
Severity: ❌ blocker / Also noticed and not raised: Session id: cron:clickhouse-review-slot-8:20260921-122500 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260921-105900 |
|
Workflow [PR], commit [c838a0d] Summary: ✅
AI ReviewSummaryThe PR masks Azure SAS signatures and case variants of AWS/GCS query parameters, shares S3 parameter classification with backup metadata redaction, and extends HTTP error credential scrubbing. No actionable findings remain at head Final Verdict✅ Approve. |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - b02401fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Session id: cron:our-pr-ci-monitor:20260921-200127 |
ClickHouse#123364 moved the S3 secret-argument code out of `src/Parsers/FunctionSecretArgumentsFinder.{cpp,h}` into `src/Storages/ObjectStorage/S3/S3SecretArguments.cpp`, so the two "mirrors `BackupInfo::removeCredentialsFromS3URL`" sentences this branch corrected are now dropped there. `maskPresignedURLParameters` takes master's `HIDDEN_SECRET` placeholder. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…on messages `S3::URI` folds a query that is not a presigned one into the key, and `Poco::URI::toString` re-encodes the decoded path, so `?%73ig=...` renders as `?%2573ig=...`. `maskedURIString` and `RemoteHostFilter::checkURL` undid only the `%3F`, so `maskPresignedURLParameters`, which decodes a name once, saw `%73ig` and the signature reached the `Invalid S3 key` and `UNACCEPTABLE_URL` messages in clear while the key half of the same message was masked. Undo the `%25` too, after the `%3F`, so a `%253F` written in a key does not turn into a separator. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Poco::URI::toString` appends a raw query as is, and a query folded into an S3 path leaves none, so the `%25` undo now runs only when there is no raw query: a URL that kept its query is shown as written (`?foo=%25bar` stays) and a name like `%2573ig` keeps the single decoding pass. The `Invalid S3 key` row in `05256` cannot reach `RemoteHostFilter::checkURL` (the key is rejected first), so `test_allowed_url_from_config` gains the encoded `?%73ig=` case for the host-filter error. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CI finish ledger - ca3d9a3Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
Both Session id: cron:our-pr-ci-monitor:20261009-200011 |
…-sas-signature-parameter Kept master's new `RemoteHostFilter::checkURL(uri, throw_on_error)` structure and applied the PR's `%25` unescaping for an S3 URI query folded into the path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…case `maskPresignedURLParameters` compared the `X-Amz-` and `X-Goog-` prefixes case-sensitively. They are header names hoisted into the query, and botocore's SigV2 presigning (`signature_version='s3'`) lower-cases every `x-amz-*` header into it, so a URL presigned with temporary credentials carries `x-amz-security-token=<STS token>`. Every sink that masks URLs through this helper printed it verbatim, while the canonical `X-Amz-Security-Token` was hidden. On 26.8.28.14 and 26.9.19.9 the token reached `system.query_log` (`query` and `exception`) for an `s3()` URL; on master also the `Settings` map for `s3_base` and the error of a failed `url()` request. The prefixes now match ASCII-case-insensitively. The exact names keep matching as spelled: they are query-only names that every signer emits canonically, and `sig` is case-sensitive on purpose (Azurite rejects `?SIG=`). The percent-decoded pass goes through the same predicate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`BackupInfo::removeCredentialsFromS3URL` builds the `<base_backup>`
locator that an incremental backup writes into its `.backup` metadata.
It matched `X-Amz-` and `X-Goog-` case-sensitively, so for a SigV2
presigned base URL (`...?AWSAccessKeyId=..&Signature=..&x-amz-security-token=T&Expires=..`)
it removed three names and kept `x-amz-security-token=T`. The STS
session token was persisted in the backup metadata, and the leftover
query is no longer presigned to `S3::URI`, which then reads it as part
of the key: a restore that copies the credentials onto that locator
fails with `Backup S3('.../base?x-amz-security-token=T', ...) not found`.
The `X-Amz-` and `X-Goog-` names are now removed in any case, but only
when the query is presigned by the existing case-sensitive set, because
`S3::URI` ignores the query of a presigned URL only. A query that is
not presigned is part of the key, so `.../backup?x-amz-foo=bar` keeps
its query and still opens the same object on restore.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
`S3::URI` reads no key from the query when it carries `versionId` or a presigned name, but `BackupInfo::removeCredentialsFromS3URL` removed the `X-Amz-`/`X-Goog-` names in any case only for a presigned query. So `.../backup?versionId=v1&x-amz-security-token=T` kept the token in the `<base_backup>` locator written to the backup metadata, although removing it opens the same key and version (the canonical `X-Amz-Security-Token` of the same URL was already removed). The gate now uses the same predicate as `S3::URI`; `versionId` itself is kept. The `X-Goog-` half of that rule gets a test with a GCS V2 presigned locator, and a doc sentence in `maskURIPassword.h` no longer claims that `BackupInfo` skips decoded names (it reads names through `Poco::URI`, which decodes them). Co-Authored-By: Claude Opus 5.5 <[email protected]>
Drop a comment that narrated the decoder's design, and condense the decoding, regex-equivalence and SAS notes in maskURIPassword.h. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Review of the added commits (
|
|
cc @jkartseva, could you review the |
CI finish ledger - c209e5fEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
All four Session id: cron:our-pr-ci-monitor:20261017-230009 |
…nature-parameter # Conflicts: # tests/integration/test_allowed_url_from_config/test.py
Reuse `decodeQueryComponent` instead of a second percent decoder, keep the name matcher inside `maskPresignedURLParameters`, drop the no-op `%` skips in the differential gtests, and check the Azure SAS masking in `05056` with one `getSetting` query instead of two `query_log` polling loops. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`S3::URI`, `BackupInfo::removeCredentialsFromS3URL` and `maskPresignedURLParameters` each spelled the same list of presigned query parameter names. They now share `isPresignedURLParameterName`, which matches the `X-Amz-`/`X-Goog-` prefixes in any case, so the lower-case SigV2 `x-amz-security-token` is handled the same in all three. `presignedURLCredentials` keeps its narrower list next to it and now also scrubs the Azure SAS `sig` and the GCS signature and key id. `maskS3URICredentials` duplicated `maskURICredentials` and is removed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The container in `abfss://c@...` reads as userinfo and is hidden, which is not what the check is about. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Algunenano
left a comment
There was a problem hiding this comment.
I've made a few tweaks to simplify the code and unify lists of parameters. Looks fine now
Move the `SettingsSecrets.h` masking bodies into the .cpp so including the header does not pull URL masking into every translation unit, and stub `renderSecretSettingValue` in the WASM build, which formats with secrets shown. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Related: #121257
Related: #126229
sig, the HMAC of an Azure shared access signature, was printed in cleartext wherever a URL query is masked by name (url_base,s3_base,format_avro_schema_registry_url,s3/urlarguments,S3::URIandremote_url_allow_hostserrors), while the AWS and Google presigned parameters were hidden. The same happened tox-amz-security-token, the lower-case spelling botocore uses for the session token of a SigV2 presigned URL, which was also kept in the base-backup locator written into an incremental backup.The presigned parameter names were spelled out separately in
S3::URI,BackupInfo::removeCredentialsFromS3URLandmaskPresignedURLParameters. They now shareisPresignedURLParameterName, which matches theX-Amz-/X-Goog-prefixes in any case.maskPresignedURLParametersaddssigand matches names percent-decoded, as the storage endpoint reads them (?%73ig=authenticates like?sig=against Azurite,?SIG=does not).presignedURLCredentials, which scrubs echoed credentials from HTTP error bodies, now also coverssig,X-Goog-Signature,GoogleAccessIdand the key id inX-Goog-Credential.maskS3URICredentialsduplicatedmaskURICredentialsand is removed.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The
sigparameter of an Azure shared access signature in a URL (url_base,s3_base,format_avro_schema_registry_url,s3andurlarguments, and error messages) is now replaced with[HIDDEN]insystem.query_log,system.settings,system.processesand settings profiles, like the AWS and Google presigned parameters.X-Amz-*andX-Goog-*parameters are now hidden in any letter case, so the lower-casex-amz-security-tokenof a SigV2 presigned URL is no longer shown or kept in the base-backup locator of an incremental backup.Workflow [PR]
Sync PR [sync-upstream/pr/121348]
Version info
26.11.1.591-master(included in26.11and later)