Skip to content

Cherry pick #122673 to 26.7: Hide HTTP headers of HTTP dictionary sources - #123257

Merged
robot-clickhouse-ci-2 merged 13 commits into
backport/26.7/122673from
cherrypick/26.7/122673
Oct 1, 2026
Merged

robot-clickhouse-ci-2 merged 13 commits into
backport/26.7/122673from
cherrypick/26.7/122673

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

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-pick locally.
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:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

Manerone and others added 12 commits September 28, 2026 12:46
`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]>
…values

Hide HTTP headers of `HTTP` dictionary sources
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request labels Oct 1, 2026
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]>
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 merged commit 6b364ef into backport/26.7/122673 Oct 1, 2026
1 check passed
@robot-clickhouse-ci-2
robot-clickhouse-ci-2 deleted the cherrypick/26.7/122673 branch October 1, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants