Repository navigation
Hide HTTP headers of HTTP dictionary sources - #122673
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]>
|
Workflow [PR], commit [3bf9b84] Summary: ✅
AI ReviewSummaryThis PR correctly hides Findings❌ Blockers
Final VerdictChanges requested. The header masking itself looks sound, but the current PR head still leaves the LLVM Coverage ReportMeasured on commit 3bf9b84.
Changed lines: Changed C/C++ lines covered: 13/14 (92.86%) · Uncovered code |
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
left a comment
There was a problem hiding this comment.
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]>
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline. |
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]>
HTTP dictionary sourcesHTTP dictionary sources
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]>
|
While working on this PR, I found a few problems with dictionary source definitions that already exist on 1.
|
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]>
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]>
Cherry pick #122673 to 26.3: Hide HTTP headers of `HTTP` dictionary sources
Cherry pick #122673 to 26.7: Hide HTTP headers of `HTTP` dictionary sources
Backport #122673 to 26.9: Hide HTTP headers of `HTTP` dictionary sources
Backport #122673 to 26.8: Hide HTTP headers of `HTTP` dictionary sources
Backport #122673 to 26.7: Hide HTTP headers of `HTTP` dictionary sources
…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]>
…onary sources
…onary sources
Backport #122673 to 26.3: Hide HTTP headers of `HTTP` dictionary sources
Problem
Custom HTTP headers of an
HTTPdictionary source often carry credentials such as API tokens. They were printed in plain text bySHOW CREATE DICTIONARY, insystem.tables.create_table_query, and in the text of theCREATE DICTIONARYquery insystem.query_logandsystem.text_log. The password of the same source was already hidden:Before:
Any user who can run
SHOW CREATE DICTIONARY, readsystem.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:
The same applies to
system.tables.create_table_queryand to the logged text of theCREATE DICTIONARYquery insystem.query_logandsystem.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
HTTPDictionarySourcevalidates the structure ofheaders(...), so a malformed definition is logged as written. Keeping the names would require deciding which parts ofheader(...)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 CREATEcan see the headers the same way. All three of these are required:The server setting
display_secrets_in_show_and_select(off by default) enables showing secrets at all:The user needs the
displaySecretsInShowAndSelectprivilege:The format setting
format_display_secrets_in_show_and_selectturns it on for a query or session: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 onlyquery_masking_rulesapplied.Implementation
headersandheaderare secret keys ofASTPair, likepassword, soASTPair::formatImplprints their value as'[HIDDEN]', andASTPair::hasSecretPartsmakesexecuteQuerylog the masked query text.ASTPair::readJSONlower-cases the keys the same way as the SQL parser, so withdialect = 'clickhouse_json'a mixed-case AST (HEADERS,PASSWORD,URI) cannot bypass the masking. The mixed-case bypass ofPASSWORDandURIpredates this PR.Compatibility: users who relied on seeing the headers in
SHOW CREATE DICTIONARYorsystem.tableswill now seeHEADERS ('[HIDDEN]'), unless they use the settings above.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Hide the HTTP headers in the definition of
HTTPdictionary sources inSHOW CREATE DICTIONARY,system.tablesand query logs, the same way as passwords. They can be shown with the existingdisplay_secrets_in_show_and_selectmechanism.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/122673]
Version info
26.10.1.1091-master(included in26.10and later)26.9.8.12,26.8.15.25,26.7.20.8,26.3.39.9