Skip to content

Hide HTTP headers of HTTP dictionary sources - #122673

Merged
Manerone merged 11 commits into
ClickHouse:masterfrom
Manerone:hide-http-dictionary-header-values
Sep 30, 2026
Merged

Manerone merged 11 commits into
ClickHouse:masterfrom
Manerone:hide-http-dictionary-header-values

Conversation

@Manerone

@Manerone Manerone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Custom HTTP headers of an HTTP dictionary source often carry credentials such as API tokens. They were printed in plain text by SHOW CREATE DICTIONARY, in system.tables.create_table_query, and in the text of the CREATE DICTIONARY query in system.query_log and system.text_log. The password of the same source was already hidden:

CREATE DICTIONARY d (id UInt64, v String)
PRIMARY KEY id
SOURCE(HTTP(
    url 'http://example.com/data.tsv'
    format 'TabSeparated'
    credentials(user 'user' password 'password')
    headers(header(name 'API-KEY' value 'secret-token'))
))
LIFETIME(0) LAYOUT(FLAT());

SHOW CREATE DICTIONARY d;

Before:

... CREDENTIALS (USER 'user' PASSWORD '[HIDDEN]') HEADERS (HEADER (NAME 'API-KEY' VALUE 'secret-token'))))

Any user who can run SHOW CREATE DICTIONARY, read system.tables, or read the query logs could see the token.

Fix

The headers are now hidden as a whole, including their names, everywhere the password is hidden:

... CREDENTIALS (USER 'user' PASSWORD '[HIDDEN]') HEADERS ('[HIDDEN]')))

The same applies to system.tables.create_table_query and to the logged text of the CREATE DICTIONARY query in system.query_log and system.text_log. The dictionary itself is unaffected: the metadata on disk keeps the real headers, the headers are still sent with every request, and the dictionary is re-created correctly after a server restart.

The headers are hidden by default, with no opt-in flag, so existing dictionaries are protected as well.

The names are hidden too, because the query is logged before HTTPDictionarySource validates the structure of headers(...), so a malformed definition is logged as written. Keeping the names would require deciding which parts of header(...) are safe to show, and a misspelled key (header(name 'X' vaule 'secret-token')), a function (name concat('X-', 'secret-token')) or a collection (name ['secret-token']) would all put the token into the logs. Hiding the whole value leaves nothing to inspect.

Showing the headers

Users who are allowed to see passwords in SHOW CREATE can see the headers the same way. All three of these are required:

  1. The server setting display_secrets_in_show_and_select (off by default) enables showing secrets at all:

    <clickhouse>
        <display_secrets_in_show_and_select>1</display_secrets_in_show_and_select>
    </clickhouse>
  2. The user needs the displaySecretsInShowAndSelect privilege:

    GRANT displaySecretsInShowAndSelect ON *.* TO admin;
  3. The format setting format_display_secrets_in_show_and_select turns it on for a query or session:

    SHOW CREATE DICTIONARY d SETTINGS format_display_secrets_in_show_and_select = 1;
    ... CREDENTIALS (USER 'user' PASSWORD 'password') HEADERS (HEADER (NAME 'API-KEY' VALUE 'secret-token'))))
    

If any of the three is missing, the output stays HEADERS ('[HIDDEN]'). These settings do not affect the query logs, which always keep the headers hidden for queries that parse. As with passwords, a query that cannot be parsed at all is logged as written, with only query_masking_rules applied.

Implementation

  • headers and header are secret keys of ASTPair, like password, so ASTPair::formatImpl prints their value as '[HIDDEN]', and ASTPair::hasSecretParts makes executeQuery log the masked query text.
  • ASTPair::readJSON lower-cases the keys the same way as the SQL parser, so with dialect = 'clickhouse_json' a mixed-case AST (HEADERS, PASSWORD, URI) cannot bypass the masking. The mixed-case bypass of PASSWORD and URI predates this PR.

Compatibility: users who relied on seeing the headers in SHOW CREATE DICTIONARY or system.tables will now see HEADERS ('[HIDDEN]'), unless they use the settings above.

Changelog category (leave one):

  • Improvement

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

Hide the HTTP headers in the definition of HTTP dictionary sources in SHOW CREATE DICTIONARY, system.tables and query logs, the same way as passwords. They can be shown with the existing display_secrets_in_show_and_select mechanism.

🤖 Generated with Claude Code


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

Version info

  • Merged into: 26.10.1.1091-master (included in 26.10 and later)
  • Backported to: 26.9.8.12, 26.8.15.25, 26.7.20.8, 26.3.39.9

`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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [3bf9b84]

Summary: ✅


AI Review

Summary

This PR correctly hides HTTP dictionary headers in SHOW CREATE DICTIONARY, system.tables, and parsed-query logging paths, and the mixed-case clickhouse_json masking bypass is fixed. I still cannot clear it for merge because the final ASTPair::readJSON revision again accepts parser-impossible dictionary shapes, so the touched clickhouse_json path can still persist unparsable metadata or crash in dictionary configuration building.

Findings

❌ Blockers

  • [src/Parsers/ASTFunctionWithKeyValueArguments.cpp:59-74, src/Dictionaries/getDictionaryConfigurationFromAST.cpp:595-622, src/Databases/DatabaseOnDisk.cpp:205-230, src/Parsers/ExpressionListParsers.cpp:484-507] [dismissed by author -- https://github.com/Hide HTTP headers of HTTP dictionary sources #122673#discussion_r4133890830; https://github.com/Hide HTTP headers of HTTP dictionary sources #122673#discussion_r4134478337] ParserKeyValuePair guarantees "ASTExpressionList of ASTPair iff second_with_brackets", but the final PR head no longer enforces either direction in ASTPair::readJSON. A crafted clickhouse_json CREATE DICTIONARY can therefore still store HEADERS HEADER(...) / HEADER ('token') text that the SQL parser cannot reload after restart, and second = ExpressionList([Literal(...)]) still reaches buildConfigurationFromFunctionWithKeyValueArguments where pair->first is dereferenced through null. This remains reachable on the changed code path even if it also exists on master. Suggested fix: restore the parser-shape validation in ASTPair::readJSON (second_with_brackets must match list-vs-scalar, and list elements must all be ASTPair), keep a defensive null/type check before recursing in buildConfigurationFromFunctionWithKeyValueArguments, and re-add the malformed-JSON regression cases dropped from 05142_http_dictionary_hide_header_values_json.sh.
Final Verdict

Changes requested. The header masking itself looks sound, but the current PR head still leaves the clickhouse_json dictionary-deserialization crash / unrestartable-metadata bug in the exact code it touches. No new inline comments were posted because this blocker is already covered by existing author-dismissed threads and the review instructions require it to stay in the summary instead of being re-posted inline.

LLVM Coverage Report

Measured on commit 3bf9b84.

Metric Baseline Current Δ
Lines 88.20% 88.20% +0.00%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.60% +0.00%

Changed lines: Changed C/C++ lines covered: 13/14 (92.86%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Sep 28, 2026
@Manerone Manerone added the can be tested Allows running workflows for external contributors label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). label Sep 28, 2026
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]>

@diegomestre2 diegomestre2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I added some suggestions that are not mandatory, only if you find them necessary. Great work!

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]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 3bf9b842a with master 09baa85ae (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline.

Job report

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]>
Manerone and others added 2 commits September 29, 2026 11:28
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]>
@Manerone Manerone changed the title Hide HTTP header values of HTTP dictionary sources Hide HTTP headers of HTTP dictionary sources Sep 29, 2026
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]>
@Manerone

Copy link
Copy Markdown
Contributor Author

@groeneai

While working on this PR, I found a few problems with dictionary source definitions that already exist on master. They are out of scope here and need a separate issue. Items 1a, 1b and 2 (up to CREATE) were reproduced on a debug build of this branch; the code involved is the same on master. Item 1c and the load part of item 2 are not verified.

1. clickhouse_json: ASTPair::readJSON doesn't enforce the parser's shape rules

The SQL parser (ParserKeyValuePair) sets second_with_brackets = true exactly when second is an ASTExpressionList of ASTPairs. ASTPair::readJSON checks none of this, so a JSON AST can create shapes the parser never produces. This affects every bracketed key of a dictionary source (headers, credentials, replica, ...), not only headers. It needs enable_json_ast_dialect and the right to create dictionaries.

a) A list without brackets: the server can't restart (reproduced). Take parseQueryToJSON of a valid CREATE DICTIONARY ... headers(header(name 'API-KEY' value 'TOKEN')), change "first":"headers","second_with_brackets":true to false, and run it with clickhouse-client --enable_json_ast_dialect 1 --dialect clickhouse_json. The CREATE succeeds, because buildConfigurationFromFunctionWithKeyValueArguments ignores the flag. The metadata is saved as ... HEADERS HEADER (NAME 'API-KEY' VALUE 'TOKEN'))), which is invalid SQL, and the server no longer starts:

Caught exception while loading metadata: Code: 62. DB::Exception: Syntax error (in file store/.../d.sql): failed at position 181 ('API-KEY')

b) Brackets around a single value: unreadable metadata, and the value shows up in error messages (reproduced). Same steps with headers(header 'TOKEN'), changing "first":"header","second_with_brackets":false to true. The CREATE succeeds. system.tables.create_table_query is then empty for the dictionary, and SHOW CREATE DICTIONARY fails with a syntax error that quotes the stored value:

Syntax error (in file store/.../d.sql): failed at position 177 ('TOKEN')

A restart presumably fails as in a); not tested.

c) A list element that isn't a pair: null pointer dereference (from reading the code). headers with second_with_brackets = true and second = ExpressionList([Literal('x')]). buildConfigurationFromFunctionWithKeyValueArguments (src/Dictionaries/getDictionaryConfigurationFromAST.cpp:594-595) calls child->as<const ASTPair>() and then uses pair->first without checking for null, which would take the server down.

A possible fix: make ASTPair::readJSON require "a list of ASTPairs if and only if second_with_brackets" and throw BAD_ARGUMENTS otherwise, and add a null check in the builder.

2. CREATE DICTIONARY accepts malformed headers(...)

The structure of headers(...) is not checked when the dictionary is created. All of these parse and CREATE successfully:

headers()
headers(header(value '1'))                 -- no name
headers(header(name 'X-A' vaule '1'))      -- misspelled key
headers(header(secret '1'))                -- unknown key
headers(foo '1')                           -- no header(...)
headers 'X-A: 1'                           -- plain string
headers(header 'X-A: 1')
headers(header(name(foo '1')))             -- nested pairs
headers(header(name 1 value 2))            -- numbers

Only a function or a collection as name is rejected at CREATE, with INCORRECT_DICTIONARY_DEFINITION and BAD_ARGUMENTS respectively.

To investigate: what happens when these dictionaries load. Do invalid keys raise an error, or are they silently ignored? For example, a misspelled vaule might mean the header is sent with an empty value. HTTPDictionarySource.cpp has an allow-list with headers.header.name and headers.header.value; it's unclear whether it covers nested keys. A possible fix is to validate the structure at CREATE time.

@Manerone
Manerone added this pull request to the merge queue Sep 30, 2026
Merged via the queue into ClickHouse:master with commit 4995011 Sep 30, 2026
149 checks passed
@Manerone
Manerone deleted the hide-http-dictionary-header-values branch September 30, 2026 16:25
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 30, 2026
@Manerone Manerone added pr-must-backport Pull request should be backported intentionally. Use this label with great care! and removed pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Sep 30, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 1, 2026
Manerone added a commit that referenced this pull request 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]>
Manerone added a commit that referenced this pull request Oct 1, 2026
Resolve the conflicts of the cherry-pick of #122673 to 26.3. 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.

26.3 does not accept an array literal as a dictionary source parameter, so
remove the `d_05141_array` case from the test: it would be a syntax error, and
unparsable queries are logged as written.

Original pull request: #122673

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 1, 2026
Cherry pick #122673 to 26.3: Hide HTTP headers of `HTTP` dictionary sources
robot-clickhouse-ci-2 added a commit that referenced this pull request Oct 1, 2026
Cherry pick #122673 to 26.7: Hide HTTP headers of `HTTP` dictionary sources
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 1, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 1, 2026
Backport #122673 to 26.9: Hide HTTP headers of `HTTP` dictionary sources
clickhouse-gh Bot added a commit that referenced this pull request Oct 1, 2026
Backport #122673 to 26.8: Hide HTTP headers of `HTTP` dictionary sources
clickhouse-gh Bot added a commit that referenced this pull request Oct 1, 2026
Backport #122673 to 26.7: Hide HTTP headers of `HTTP` dictionary sources
alexey-milovidov pushed a commit to rorylshanks/ClickHouse that referenced this pull request Oct 2, 2026
…ser cannot produce

`IAST::createFromJSON` rebuilds a `CREATE DICTIONARY` through the per-node
`readJSON`s, not through the parser, so a JSON AST can carry shapes that
`ParserKeyValuePair`, `ParserDictionary` and `ParserCreateDictionaryQuery` never
produce. The dictionary configuration builder decides structure by node type and
ignores the bracket flags, while the formatter writes the stored metadata from
those flags. Measured on master and on the official 26.9.1.1629:

- a pair whose value is a list of pairs but `second_with_brackets = false`, a
  single value with `second_with_brackets = true` (also a `LAYOUT` parameter),
  and a `SOURCE` with `has_brackets = false` are accepted and stored as SQL that
  does not parse back: `SHOW CREATE` fails with `Code: 62` and the server no
  longer starts (`Caught exception while loading metadata`);
- a bracketed list element that is not a pair, a `DEFAULT` that is not a
  literal and a definition without attributes hit unchecked `as<T>` in
  `getDictionaryConfigurationFromAST` (segmentation fault at `CREATE`); an empty
  `PRIMARY KEY` aborts on `pk_attrs[0]`, and a key element that is not an
  identifier is read as one.

Each reader now enforces what its parser guarantees and throws `BAD_ARGUMENTS`:
`ASTPair` has brackets exactly when its value is a list, and such a list holds
only pairs; `SOURCE` has brackets; the primary key is a non-empty list of
identifiers; `DEFAULT` is a literal; a definition comes with its attributes.
This completes, one level down, what `c32c025279d82` (pairs in `elements`) and
`0dcd1931bf873` (layout brackets) did. SQL input is unaffected, and stored
metadata is SQL, which never passes through `readJSON`.

Closes: ClickHouse#122926
Related: ClickHouse#122673 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 2, 2026
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #122673 to 26.3: Hide HTTP headers of `HTTP` dictionary sources
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-dictionary Dictionaries (in-memory key-value, periodically refreshed from sources). pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-improvement Pull request with some product improvements pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants