Repository navigation
Cherry pick #122673 to 26.7: Hide HTTP headers of HTTP dictionary sources - #123257
Merged
robot-clickhouse-ci-2 merged 13 commits intoOct 1, 2026
Merged
Conversation
`SHOW CREATE DICTIONARY`, `system.tables.create_table_query` and the query logs printed the values of custom HTTP headers of an `HTTP` dictionary source in plain text, while the password was already hidden. Header values often carry credentials such as API tokens. Now `ASTPair::formatImpl` prints `value` inside each `header(...)` as `'[HIDDEN]'` unless secrets are displayed, keeping the header name. The masking is formatting-only: the stored metadata keeps the real value. `ASTPair::hasSecretParts` returns true for `headers` and `header`, so the `CREATE DICTIONARY` query text is masked in `system.query_log` and `system.text_log` as well. This is consistent with the `url` table function, which already hides all header values. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The secret-display settings only affect `SHOW CREATE DICTIONARY` and `system.tables`: `formatForLogging` always formats with secrets hidden, so `system.query_log` and `system.text_log` keep the header values masked. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The query is logged before `HTTPDictionarySource` rejects unknown keys, so masking only `value` inside `header(...)` leaked secrets from malformed definitions such as `header(name 'X' vaule 'TOKEN')` or `headers(foo 'TOKEN')` into `system.query_log`. Now only `name` is kept inside `header(...)`, and only `header(...)` entries are kept inside `headers(...)`; everything else, including a `header` or `headers` without brackets, is shown as `[HIDDEN]`. `ASTPair::hasSecretParts` again returns true for `headers` as well, so a `headers(...)` without any `header(...)` entry is masked in the logs too. Also apply review suggestions: fold the cast into the `if` initializer. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The masking of HTTP dictionary headers relied on the SQL-parser invariant that a pair value in brackets is an `ASTExpressionList` of `ASTPair`, but `ASTPair::readJSON` did not enforce it. With `dialect = 'clickhouse_json'`, a `header` or `headers` pair in brackets with a plain `Literal` value was formatted verbatim into the logged query text. `ASTPair::readJSON` now rejects such payloads with `BAD_ARGUMENTS`, the same way `ASTFunctionWithKeyValueArguments::readJSON` validates its elements, and `ASTPair::formatImpl` hides a `header` or `headers` value that is not a list of pairs as a whole, whatever produced the AST. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SQL parser lower-cases the keys of dictionary source pairs, and the checks for secret keys (`password`, `uri`, `header`, `headers`, ...) in `ASTPair::formatImpl` and `ASTPair::hasSecretParts` rely on it. A `clickhouse_json` AST could spell them in another case, e.g. `HEADERS` or `PASSWORD`, so `hasSecretParts` returned false and the query was logged as raw text with the secrets. `ASTPair::readJSON` now canonicalizes the key the same way as the parser. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A query that fails to parse (or to deserialize from `clickhouse_json`) is logged as is in `system.query_log` and `system.text_log`, with only `query_masking_rules` applied, the same as for passwords. Narrow the documentation of the `HTTP` dictionary source accordingly. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The fail-closed masking kept any `name` without brackets, but the parser also
accepts a function there, e.g. `header(name concat('X-', 'TOKEN'))`. Functions
are rejected only when the dictionary configuration is built, after the query
is logged, so the arguments reached `system.query_log`. Keep `name` only when
it is a literal or an identifier.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Keeping the header names visible required an allow-list of the shapes that
are safe to show inside `header(...)`, and every variant it let through
(an unknown key, a function or a collection as `name`, ...) reached the
logged query text, because the query is logged before the dictionary source
validates its structure.
Treat `headers` and `header` as secret keys, like `password`: their value is
shown as `'[HIDDEN]'` as a whole, so `SHOW CREATE DICTIONARY` prints
`HEADERS ('[HIDDEN]')` and no malformed definition can leak. This removes the
special formatting branch. The stored metadata still keeps the real headers.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The check rejected a pair in brackets whose value is not a list of pairs, because the formatter used to look inside `headers(...)` to hide only the values. Since the headers are hidden as a whole, the formatter no longer depends on that shape, so the check is not needed for masking. Validating the shapes of `clickhouse_json` ASTs in general is out of scope here. The lower-casing of the keys stays: the checks for secret keys rely on it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check every `query_log` row of the JSON test, and make the documentation say explicitly that the secret-display settings apply to the headers and do not affect the query logs. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ary-header-values
…values Hide HTTP headers of `HTTP` dictionary sources
Resolve the conflicts of the cherry-pick of #122673 to 26.7. The branch has neither `isSecretKey` from #112070 nor the AST JSON serialization from #100412, so hide `headers` and `header` through a local `isSecretKey` helper used by `ASTPair::formatImpl` and `ASTPair::hasSecretParts`, and drop the `readJSON` change, the documentation change and the `clickhouse_json` test. Original pull request: #122673 Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 #122673
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