Repository navigation
Do not abort the secret arguments finder on mixed named and positional arguments - #107818
Conversation
…l arguments
markSecretArgument() asserted that arguments are always marked in
non-decreasing index order (chassert(index >= result.start)). That holds
for well-formed queries, but the s3/gcs and azureBlobStorage finders first
scan the whole argument list for the named secret form (secret_access_key =
'...') and only afterwards mark the positional secret argument. A malformed
query that mixes both forms, e.g.
SELECT * FROM s3('url', 'a', 'b', secret_access_key = 'c')
marks the named argument (a higher index) first, then asks to mark the
earlier positional one, tripping the assertion and aborting the server.
The finder runs over arbitrary user AST while masking secrets for error
messages, query_log and SHOW CREATE, so it must never abort on adversarial
input. Make markSecretArgument() widen the masked range to cover the
requested index instead of asserting on the order. Over-masking a malformed
query is the safe direction: the secret is still hidden.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate
Session id: cron:clickhouse-worker-slot-2:20260618-012800 |
|
cc @evillique @alexey-milovidov — could you review this? It stops |
|
Workflow [PR], commit [5cad35c] Summary: ✅
AI ReviewSummaryThis PR changes Final VerdictStatus: ✅ Approve |
arm_tidy flagged the two if-branches that widen the masked range (FunctionSecretArgumentsFinder.h:91,93) under -warnings-as-errors. Rewrite them with std::max/std::min (equivalent for the size_t operands) and include <algorithm>. Co-Authored-By: Claude Opus 4.8 <[email protected]>
The chassert in markSecretArgument is compiled out in release builds, so the original abort is debug-only. In a release build the old code set count back to 0 for this exact argument order, and the malformed query still returned BAD_ARGUMENTS regardless of the fix; the release-visible regression was that the formatted/logged query no longer hid the secret. The existing test only checked the error code, which both old and new code return, so it did not catch the release-visible leak. Extend the test to flush system.query_log and assert the masked query text contains [HIDDEN] and not the literal secret values for the mixed positional + named s3/gcs forms. The query is filtered by currentDatabase() so the test stays parallel-safe (no no-parallel tag). Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (test-strengthening commit 5cad35c)
Session id: cron:clickhouse-worker-slot-1:20260618-032400 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 8/8 (100.00%) | Lost baseline coverage: none · Uncovered code |
|
Hi — this looks like a backport candidate for |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server abort (
Logical error: 'index >= result.start') when formatting a malformed query that mixes the positional and named secret-argument forms of thes3/gcstable functions, e.g.s3('url', 'a', 'b', secret_access_key = 'c').Description
Found by the AST fuzzer on PR #106189 (
AST fuzzer (amd_debug, targeted)andAST fuzzer (amd_debug, targeted, old_compatibility), STID 2508-6d1e). The crash is in pre-existing trunk code, not in that PR's changes; the coverage-driven "targeted" fuzzer just selected the secret-args masking test because the PR touchesFunctionSecretArgumentsFinder.h.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=106189&sha=d28eef2e29f7ca4e1c5dfbd225e74fecb712dd9c&name_0=PR&name_1=AST%20fuzzer%20%28amd_debug%2C%20targeted%29
Root cause:
markSecretArgument()assertedchassert(index >= result.start), i.e. that arguments are always marked in non-decreasing index order. Thes3/gcsfinders first scan the whole argument list for the named secret form (secret_access_key = '...') and mark it, then unconditionally mark the positional secret argument at an earlier index. When a malformed query supplies both forms, the named argument (higher index) is marked first, then the positional one (lower index) trips the assertion and aborts the server. The finder runs over arbitrary user AST while masking secrets for error messages,query_logandSHOW CREATE, so it must never abort on adversarial input.Fix:
markSecretArgument()now widens the masked range to cover the requested index instead of asserting on the order. Over-masking a malformed query is the safe direction; the secret is still hidden. For well-formed queries the marked range is unchanged. Because the fix is in the sharedmarkSecretArgument()primitive, it also hardens any other finder that might mark out of order. A stateless regression test (04343_secret_args_finder_mixed_named_positional) reproduces the abort without the fix and passes with it.The
azureBlobStoragefinders are not affected by this abort: they never scan the namedaccount_keyform in the positional path (only one argument is ever marked), so they cannot mark out of order.azureBlobStorageis therefore dropped from the changelog claim. The pre-existing gap that the namedaccount_keyis not masked forazureBlobStoragemixed forms is a separate masking-completeness issue, out of scope for this abort fix.Version info
26.6.1.979