Skip to content

Scrub the request's bearer token from the reason phrase of an HTTP error response - #126180

Merged
hanfei1991 merged 1 commit into
ClickHouse:masterfrom
groeneai:scrub-http-error-reason-phrase-credentials
Oct 16, 2026
Merged

hanfei1991 merged 1 commit into
ClickHouse:masterfrom
groeneai:scrub-http-error-reason-phrase-credentials

Conversation

@groeneai

@groeneai groeneai commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #125282
Related: #120407

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The reason phrase of an HTTP error response from a remote server is now scrubbed of the request's bearer token in the error message, as the response body already is.

Description

#120407 scrubs the request's bearer token from the body of an HTTP error response, but HTTPException::makeExceptionMessage still formats the reason phrase raw. A peer that answers url(..., headers('Authorization' = 'Bearer <token>')) with 401 invalid token <token> puts the token into the client error, the server log and system.query_log.exception, while the query text itself is already masked. This is the second gap named in #125282.

The change applies the existing scrub to the reason phrase as well, in the one formatter that holds the secrets and is reached by both callers that pass them (ReadWriteBufferFromHTTP for reads, receiveResponse for WriteBufferFromHTTP). The parameter body_secrets is renamed to response_secrets, since it no longer applies to the body only.

The Avro schema registry 409 branch from #125282 needs no change: the registry only sends Basic authentication, and requestCredentialSecrets returns nothing for Basic, so no registry error body is scrubbed on any status and the 409 path already matches the common one.

05401_http_error_reason_phrase_credentials_masked.py starts a local peer that reflects the token in its reason phrase and checks both the error and the system.query_log row. With only the reason scrub reverted it prints the token in cleartext; with the fix it passes, also under the parallel replicas profile.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/126180]

Version info

  • Merged into: 26.11.1.83-master (included in 26.11 and later)

…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]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 Category should be Bug Fix, since the raw reason phrase exists on 26.9 DISAGREE The leak needs a peer that puts the bearer token into its status line; no known server does, and a token over the 512-byte reason cap is rejected with no text (HTTPClientIO.cpp:159-165). Hardening, so Improvement.
2 💡 The reason phrase is still raw in the range-mismatch errors of ReadWriteBufferFromHTTP and in the status-line SyntaxException AGREE, not changed Those run only on an accepted 2xx response, or with no request in scope.
3 💡 The .py test does not receive the runner's random settings AGREE, not changed Same as 02205_HTTP_user_agent.python; the server-side parallel replicas profile still applies.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are
terminal per finding.

Session id: cron:clickhouse-review-slot-9:20261016-020600

@clickhouse-gh

clickhouse-gh Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [916614f]

Summary: ✅


AI Review

Summary

The PR extends bearer-token scrubbing from HTTP error bodies to reason phrases in HTTPException::makeExceptionMessage, with a stateless regression covering the client exception and system.query_log. No actionable findings.

Missing context / blind spots
  • ⚠️ Broader stateless and sanitizer jobs are still pending. The new regression passed in Fast test at the reviewed PR head; no local ClickHouse executable was available for an independent rerun.
Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Oct 16, 2026
@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @hanfei1991 @alexey-milovidov, could you review this? After #120407, HTTPException::makeExceptionMessage scrubs the request's bearer token from the error body only; this applies the same scrub to the reason phrase, so a peer that reflects the token in its status line no longer puts it into the exception and system.query_log.

@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Oct 16, 2026
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label Oct 16, 2026
@hanfei1991 hanfei1991 self-assigned this Oct 16, 2026
@hanfei1991
hanfei1991 added this pull request to the merge queue Oct 16, 2026
Merged via the queue into ClickHouse:master with commit 97b74a2 Oct 16, 2026
526 of 528 checks passed
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 16, 2026
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avro Confluent schema registry: the HTTP 409 branch logs and throws the registry body before credential scrubbing

4 participants