Repository navigation
Scrub the credentials of a presigned URL from the body of an HTTP error - #126229
Conversation
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]>
`presignedURLCredentials` added only the decoded key id of `X-Amz-Credential`, while the other credentials are added both as sent and percent-decoded, as the header comment promises. An endpoint echoing the query as sent (S3's `<CanonicalRequest>`) then printed a key id that was sent with an escape, e.g. `AKIA%56...`. The raw key id ends at the first `/` or `%2F`, which is exactly where the decoded one ends, and is added when it differs from the decoded one. The test sends the SigV4 key id with its `V` percent-encoded and checks both spellings, in the message and in `system.query_log`. The comment of `decodeQueryComponent` no longer claims that its result only feeds the sensitivity decision: it is also a scrub needle now. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review (two rounds on this change; the last one found nothing)
|
|
Workflow [PR], commit [1b48f73] Summary: ✅
AI ReviewSummaryThe PR scrubs presigned S3 credentials from reflected HTTP error reasons and bodies, including parallel and resumed range-read failures. Review of head Final Verdict✅ Approve. |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20261016-061900 |
|
cc @hanfei1991 @yakov-olkhovskiy, could you review this and add |
…igned-credentials-from-http-error-body # Conflicts: # src/IO/HTTPCommon.cpp
…he peer does Three defects of the presigned-URL body scrub, found by the automated review: 1. The scrub replaced each credential in turn over its own output, and kept duplicates. `[HIDDEN]` itself contains letters, so a short credential that occurs in it (`Signature=D` repeated 18 times) doubled the text on each pass: a 456-byte 403 body became a 3.67 MB exception message. Now the credentials are deduplicated, every match is located in the original text, and each covered run becomes one `[HIDDEN]`, so the output is linear in the input and a secret contained in another is still covered without ordering them by length. 2. Session tokens under other names were not extracted: botocore's SigV2 presigner emits `x-amz-security-token`, its S3 Express presigner `X-Amz-S3session-Token`. 3. Names were compared as sent, while a peer such as MinIO percent-decodes them, so `X-Amz-%53ignature=<sig>` was echoed in `<SignatureProvided>` unscrubbed. Names are now decoded and lower-cased before matching, with the helper the server-side masker in the same file already uses. The URI part of the message is still masked by `maskURICredentials`, which matches names case-sensitively as typed, so it keeps showing the lowercase SigV2 token and a percent-encoded name; that is that shared masker's policy and is not changed here. The test checks those two spellings in the body. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…HTTP `HTTPException` derives the credentials to scrub from the URI it is given, so the two range-error constructors in `initialize` and `readBigAt`, which still passed an already masked URI, scrubbed only `[HIDDEN]` and left a credential that the server reflected in its reason phrase visible in the reason and in the diagnostic body. The URI shown in the message is masked by `HTTPException` itself, as for `callImpl`. The test gains a parallel range read (`readBigAt`) and a sequential read resumed with a range after the connection is cut (`initialize`), each answered with 200 and the signature as the reason phrase. Each leg fails when only its own site is reverted. The parallel leg pins the HEAD request that tells the reader the source is seekable, and turns parallel replicas for cluster engines off, since `urlCluster` reads the file sequentially. The `query_log` check also asserts that the errors are logged with the scrubbed body, so that it cannot pass on no rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A resumed sequential read whose range GET is answered with 201, 202 or 204
passes `assertResponseIsOk` and then fails in `ReadWriteBufferFromHTTP::initialize`
with a plain `Exception` that printed the remote reason phrase verbatim, so a
reflected presigned signature reached the client, the server log and
`system.query_log` while the URI next to it was masked. Its reason is now
scrubbed with the same credentials as `HTTPException`, through a small
`scrubRequestCredentials` helper. The exception type is unchanged, so it is
still not retried (measured: one range request with `http_max_tries = 5`).
The three range errors (this one, the retried 200 in `initialize`, and
`readBigAt`) also passed no request secrets, unlike `callImpl`, so a bearer
token from `headers('Authorization' = 'Bearer ...')` reflected in the reason
phrase survived. They now scrub the bearer token of the request's headers too.
Test 05404: a `select_resumed_range_201` leg; the range legs send a bearer
token that the mock reflects next to the signature. The mock now binds a free
port itself and reports it through a file, instead of the shell probing a port
and freeing it again, which lost 1 of 50 parallel runs to `Address already in
use`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units151 translation units recompiled, 1153 s compile time in total, 151 of them have a recent master baseline. |
The mock closed the connection after its HEAD reply on the range endpoint without sending `Connection: close`, so the client returned that connection to the pool. A range GET of the parallel read could borrow it before the close reached the client, so the pool's staleness check passed, and fail with `No message received` ahead of the 416 the leg checks. That is the one failure in 46 runs of `Stateless tests (amd_tsan, s3 storage, targeted)`. With the header the client does not pool the connection. Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov
left a comment
There was a problem hiding this comment.
Ok. We go a really long way to find sensitive parameters...
Related: #120407
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Hide the credentials of a presigned S3 URL that the remote server echoes in its error response body, such as the access key id and the signature in a
SignatureDoesNotMatcherror, in the exception of a failed HTTP request,system.query_logand the server log.Description
On 26.9.11.2, a
url()read or write of a presigned S3 URL that S3 rejects withSignatureDoesNotMatchprints the request's access key id and signature: S3 echoes them in<AWSAccessKeyId>and<SignatureProvided>, and that body is copied into the exception, which reaches the client,system.query_logand the server log. This is the second half of #120407 (comment).#120407 masks the URI and scrubs the request's own credential strings from the body, but only an
Authorization: Bearertoken feeds that list. A presigned URL sends its credentials in the query string, so the message showsX-Amz-Signature=[HIDDEN]in the URI and the same signature in the body.HTTPException::makeExceptionMessagenow takes the presigned credentials from the URI it already masks (X-Amz-Signature,X-Amz-Security-Token, S3 ExpressX-Amz-S3session-Token,Signature,AWSAccessKeyIdand the key id ofX-Amz-Credential; names matched percent-decoded and case-insensitively, values as sent and percent-decoded) and scrubs them from the reason phrase and the body together with the Bearer token, in one linear pass. The work runs only when anHTTPExceptionis built.ReadWriteBufferFromHTTP::callImplpasses the raw URI, asreceiveResponsedoes, and its range errors, including the plain one for a range GET answered with 201, 202 or 204, scrub the same credentials and the Bearer token; the printed URI is unchanged.Not covered: GCS names (
X-Goog-*,GoogleAccessId); S3's<CanonicalRequestBytes>hex dump (the key id and the session token, not the signature); and a lower-case or percent-encoded name in the URI part, which #121348 handles in the URI masker.The test answers like S3 from a local endpoint (SigV4
SELECTandINSERT, SigV2, a signature inside the session token, the other token names, an encoded name, a repeated one-letter signature, range reads reflecting the signature and a Bearer token in the reason phrase). Every leg fails on master and passes with this change.Workflow [PR]
Sync PR [sync-upstream/pr/126229]
Version info
26.11.1.183-master(included in26.11and later)