Repository navigation
Hide secret arguments in EXPLAIN AST output - #120313
Conversation
`EXPLAIN AST optimize = 1` inlines the definition of a view the user may `SELECT` from and dumps the result through `DumpASTNode`, which prints every literal verbatim. A user holding only `SELECT` on a `SQL SECURITY DEFINER` view could therefore read the definer's `encrypt` key that `SHOW CREATE VIEW` masks for the same user. The secret arguments found by `FunctionSecretArgumentsFinderAST` are now replaced with `'[HIDDEN]'` literals before the dump, under the same gate as `SHOW CREATE`, for the tree and the `graph = 1` output alike and for `optimize = 0` as well. Closes: ClickHouse/clickhouse-private#72669 Related: ClickHouse#118129
The visitor and call-site comments now say in short sentences what the dump cannot do and why the tree is edited instead. The test header reads the same way. No behaviour change.
The dump looked for a `key = value` pair inside every secret argument and kept the key visible.
`SHOW CREATE` does that only for a named argument and hides a positional one whole. A positional
secret written as a comparison, such as `encrypt('aes-128-ecb', 'plain', 'k1' = 'k2')`, therefore
showed its left operand. The dump now peels the value only when the finder reports the argument
as named, or when it is an entry of a nested map such as `headers(...)`.
|
Workflow [PR], commit [7d2aa10] Summary: ✅
AI ReviewSummaryThis PR correctly moves Findings❌ Blockers
Final VerdictChanges requested: the AST redaction is still incomplete, so LLVM Coverage ReportMeasured on commit 7d2aa10.
Changed lines: Changed C/C++ lines covered: 45/74 (60.81%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (+22.28 KiB total), 0 added.
716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units7 translation units recompiled, 13 s compile time in total, 7 of them have a recent master baseline. |
Fgrtue
left a comment
There was a problem hiding this comment.
I guess this is one real concern that worth adding: #120313 (comment)
This would be consistent with how EXPLAIN SYNTAX does it.
Other than that looks good.
`HideSecretArgumentsMatcher` ran `hideLiteralsInSubtree` on every secret slot, so a slot that `markSecretArgument` marks because the finder cannot read it (a url built by `concat(...)`, an identifier in a password slot, a positional secret written as a comparison) still dumped its expression node by node: `Function concat`, `Function equals`, `Identifier ...`. That is part of a `SQL SECURITY DEFINER` view body. Such a slot is now one `'[HIDDEN]'` literal, as `ASTFunction::formatImpl` prints it. A partially masked argument (a URL with its credentials removed, the reconstructed `S3(...)` of a `Backup` database) is re-parsed from the formatter text instead of walked. `hideLiteralsInSubtree` is kept only for the `encrypt` / `HMAC` key, where the expression shape is not a secret. The test prints the full AST for the fail-closed shapes so the collapse to a single node is visible. Review: ClickHouse#120313 (comment)
Keep `EXPLAIN AST` secret masking and the upstream removal of obsolete plan-secret checks. Co-authored-by: Copilot App <[email protected]>
98fbe80 to
dd27abc
Compare
The upgrade check failed on the old base because master has since disabled the AI function quotas by default, so the previous release and this branch disagreed on the defaults of `ai_function_max_*_per_query`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Note
Copilot was unable to run its full agentic suite in this review.
Copilot review overview
Review effort: Lite
Findings: 4
Open (4)
Passingmax_query_size = 0removes an important guardrail when re-parsing masked argument text.… · New AftertryParseQuery(...)succeeds, this code does not verify that the entiretextwas consumed… · New This test script doesn’t enable strict bash mode (e.g.,set -euo pipefail). In particular,… · New The.referenceoutput hardcodesdefault.private_plaintext, but the test uses… · New
What changed in this PR
Prevent EXPLAIN AST from leaking secrets (e.g., encrypt keys) by masking secret function arguments in the AST dump under the same canDisplaySecrets gate used by SHOW CREATE.
Changes:
- Add an AST visitor in
InterpreterExplainQuerythat rewrites secret argument subtrees/literals to'[HIDDEN]'before dumping. - Parse and replace certain secret arguments with pre-masked textual forms (e.g., URL credentials stripping) and fail-closed to
'[HIDDEN]'if parsing fails. - Add a stateless regression test validating masking for optimized AST, graph output, inlined view bodies, URL cases, and nested maps.
| File | Description |
|---|---|
src/Interpreters/InterpreterExplainQuery.cpp |
Masks secret arguments by mutating the AST before DumpASTNode/graph dumping when secrets cannot be displayed. |
tests/queries/0_stateless/05219_explain_ast_hide_secrets.sh |
Adds a regression test scenario covering view inlining and secret masking behavior in multiple EXPLAIN AST modes. |
tests/queries/0_stateless/05219_explain_ast_hide_secrets.reference |
Captures expected masked AST output ('[HIDDEN]') for the new regression test. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…t` / `HMAC`
The visitor treated every unnamed secret span without a replacement as the
`encrypt` / `HMAC` span and hid only the literals inside it. `mongodb` with
two arguments produces the same shape when the finder cannot read the url,
so `EXPLAIN AST` of `mongodb(concat('mongodb://user:', password_column, '@host/db'), 'c')`
still dumped `Function concat` and `Identifier password_column`.
`SHOW CREATE` prints `'[HIDDEN]'` for the whole argument there.
Keep the structure only for the functions the finder masks as
`encrypt` / `HMAC`, and hide any other such slot whole.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
0a7853b
|
@harikrishnan94 @Fgrtue — ClickGap found the following in this PR:
Close anything that's wrong or already addressed. |
…he sealed one A `SQL SECURITY DEFINER` view over a Memory table is sealed, so the legacy rewrite behind `EXPLAIN AST optimize = 1` no longer inlines its body and the reference from PR ClickHouse#120313 stopped matching. The test table becomes a `MergeTree`, which keeps the view transparent and the masking of the inlined body under test, and a second view with a WHERE pins that a sealed view is printed as a `TableIdentifier`. CI: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=122330&sha=7d01b1f68237e134cc8ca7d650d4f2df49915d4b&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 Co-Authored-By: Claude Fable 5.1 <[email protected]>
Cherry pick #120313 to 26.3: Hide secret arguments in `EXPLAIN AST` output
Cherry pick #120313 to 26.7: Hide secret arguments in `EXPLAIN AST` output
Cherry pick #120313 to 26.8: Hide secret arguments in `EXPLAIN AST` output
Cherry pick #120313 to 26.9: Hide secret arguments in `EXPLAIN AST` output
Backport #120313 to 26.7: Hide secret arguments in `EXPLAIN AST` output
Backport #120313 to 26.8: Hide secret arguments in `EXPLAIN AST` output
Backport #120313 to 26.3: Hide secret arguments in `EXPLAIN AST` output
Backport #120313 to 26.9: Hide secret arguments in `EXPLAIN AST` output
The prerequisite #120313 (`EXPLAIN AST` secret hiding) reached 26.3 through #123453 after this cherry-pick was created, so merge 26.3 first. The only remaining conflict is the include list: keep 26.3's includes and add `Parsers/ASTWithAlias.h`, which the fix needs. `ASTSubquery.h` and `ASTTablesInSelectQuery.h` are master-only context and are not needed here. Backport of #122870 Co-Authored-By: Claude Opus 5.5 <[email protected]>

Related: #118129
EXPLAIN AST optimize = 1inlines the definition of a view the user canSELECTfrom and dumps the result throughDumpASTNode.ASTLiteral::getIDembeds the literal value, so nothing masks it. A user with onlyGRANT SELECTon aSQL SECURITY DEFINERview reads the definer'sencryptkey in clear text, whileSHOW CREATE VIEWprints'[HIDDEN]'for the same user. Reproduces at defaults. #118129 fixed the plan, pipeline, query tree and syntax legs and did not touch the AST branch.The dump cannot mask while formatting the way
ASTFunction::formatImpldoes, so the tree is edited before the dump: every literal inside a secret argument found byFunctionSecretArgumentsFinderASTbecomes a'[HIDDEN]'literal, structure kept. Anencryptkey built asleftPad('...', 16, '*')shows asleftPad('[HIDDEN]', '[HIDDEN]', '[HIDDEN]'). A named argument keeps its key, a positional one is hidden whole, and a nested map (headers(...),extra_credentials(...)) hides all of its values. The gate iscanDisplaySecrets, same asSHOW CREATE. Applied foroptimize = 0and1and forgraph = 1.Masking depends only on the gate, so
EXPLAIN ASTof the user's ownencrypt(...)prints'[HIDDEN]'now as well. That matchesEXPLAIN QUERY TREE run_passes = 0andsystem.query_log.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
EXPLAIN ASTprinted secret function arguments, such as the key ofencrypt, in clear text, and withoptimize = 1it did so for the body of a view the user may onlySELECTfrom. The dump now prints'[HIDDEN]'in their place, under the same gate asSHOW CREATE.Workflow [PR]
Sync PR [sync-upstream/pr/120313]
Version info
26.10.1.960-master(included in26.10and later)26.9.9.22,26.8.16.26,26.7.20.15,26.3.39.11