EXPLAIN AST throws LOGICAL_ERROR on Backup locator named COLUMNS
Describe what's wrong
- EXPLAIN AST of a CREATE DATABASE with a Backup engine can throw LOGICAL_ERROR instead of printing the AST.
- Trigger is a backquoted locator like
t.COLUMNSwith secrets hidden, the default viadisplay_secrets_in_show_and_select. - Expected a normal AST dump; actual is an exception, and debug or sanitizer builds abort.
- Any user without database privileges can trigger the abort with a syntactically valid CREATE/ATTACH DATABASE statement.
Root cause: replaceWithMaskedText in InterpreterExplainQuery.cpp assumes the finder's replacement always parses into an ASTWithAlias and calls setAlias unconditionally. The Backup rule in FunctionSecretArgumentsFinder.cpp builds masked text from the unquoted locator name, so a name like COLUMNS re-parses as ASTQualifiedColumnsRegexpMatcher, which is not an ASTWithAlias and throws from IAST::setAlias.
Why we believe this is a bug: InterpreterExplainQuery::executeImpl (InterpreterExplainQuery.cpp:1100-1103) -> HideSecretArgumentsMatcher::visit, span with replacement (:472) -> replaceWithMaskedText (:389). ParserExpression turns the finder's text t.COLUMNS('[HIDDEN]') into ASTQualifiedColumnsRegexpMatcher, which derives from IAST, not ASTWithAlias (ASTColumnsMatcher.h:65), so parsed->setAlias(...) (:411) hits IAST::setAlias, which always throws LOGICAL_ERROR.
Affected locations:
src/Interpreters/InterpreterExplainQuery.cpp:411— unconditionalsetAliason the parse resultsrc/Interpreters/InterpreterExplainQuery.cpp:472— span-replacement call site that receives theBackuplocator textsrc/Parsers/FunctionSecretArgumentsFinder.cpp:1409— replacement embeds the locator function name unquoted
Impact: Any user, with no privilege on databases, can make EXPLAIN AST of a syntactically valid CREATE/ATTACH DATABASE ... ENGINE = Backup(...) throw LOGICAL_ERROR; debug and sanitizer builds (and release with abort_on_logical_error) abort the server. Narrow input: the locator function must be a backquoted name that re-parses as a COLUMNS matcher.
Does it reproduce on most recent release?
Yes — confirmed on current master (commit 6ee563bcdd36ec).
How to reproduce
Run with format_display_secrets_in_show_and_select off; with it on the same query dumps fine.
# EXPLAIN AST with secrets hidden must dump a Backup database whatever its locator function is named.
for locator in '`t.func`' '`t.COLUMNS`'
do
clickhouse-client --format_display_secrets_in_show_and_select 0 --query "EXPLAIN AST CREATE DATABASE d ENGINE = Backup('db', $locator('x'))" > /dev/null && echo "$locator: ok"
doneVerified: this block reproduces on current master (6ee563bcdd36) when pasted as is.
Expected behavior
EXPLAIN AST should dump the masked Backup engine AST regardless of the locator function's name.
Expected output of the reproducer above:
`t.func`: ok
`t.COLUMNS`: okError message and/or stacktrace
When the locator name re-parses as a COLUMNS matcher, setAlias on the parsed node throws LOGICAL_ERROR and aborts debug/sanitizer builds.
Actual output of the reproducer above on master (6ee563bcdd36ec):
`t.func`: ok
Received exception from server (version 26.10.1):
Code: 49. DB::Exception: Received from localhost:19010. DB::Exception: Can't set alias '' of t.COLUMNS('[HIDDEN]'): While processing Backup('db', t.COLUMNS('[HIDDEN]')). (LOGICAL_ERROR)
(query: EXPLAIN AST CREATE DATABASE d ENGINE = Backup('db', `t.COLUMNS`('x'))), result:Fail closed when the parse result cannot carry an alias: if (!parsed || !dynamic_cast<ASTWithAlias *>(parsed.get())) { hideWholeNode(node); return; }. Trade-off: such a locator dumps as one '[HIDDEN]' literal instead of the formatter's t.COLUMNS('[HIDDEN]') text, which is stricter, never leakier.
Found during automated review of PR #120313. Severity P2 · Finding h_pr120313_002
cc @harikrishnan94 @Fgrtue (from #120313)
Source: ClickHouse/ClickHouse