Skip to content

Mask the key of keyed SipHash functions in logged queries - #133828

Merged
rschu1ze merged 1 commit into
masterfrom
mask-keyed-siphash
Nov 23, 2026
Merged

rschu1ze merged 1 commit into
masterfrom
mask-keyed-siphash

Conversation

@rschu1ze

@rschu1ze rschu1ze commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

sipHash64Keyed, sipHash128Keyed and sipHash128ReferenceKeyed were registered without a SecretArgumentsSpec, so the key (the first argument) was written in plain text to system.query_log and shown by EXPLAIN SYNTAX. A user with SELECT on system.query_log could read the key of another user and reverse the hashes of enumerable inputs.

Mark the first argument as secret, the same way HMAC does for its key, so it is formatted as '[HIDDEN]'.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

The secret first key argument of "keyed" SipHash SQL functions is now masked in system.query_log.


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

Version info

  • Merged into: 26.12.1.329-master (included in 26.12 and later)
  • Backported to: 26.11.1.2939, 26.10.12.7, 26.9.39.7, 26.8.47.4

`sipHash64Keyed`, `sipHash128Keyed` and `sipHash128ReferenceKeyed` were
registered without a `SecretArgumentsSpec`, so the key (the first
argument) was written in plain text to `system.query_log` and shown by
`EXPLAIN SYNTAX`. A user with `SELECT` on `system.query_log` could read
the key of another user and reverse the hashes of enumerable inputs.

Mark the first argument as secret, the same way `HMAC` does for its key,
so it is formatted as `'[HIDDEN]'`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [5b350ae]

Summary: ❌

job_name test_name status info comment
Finish Workflow FAIL
python3 ./ci/jobs/scripts/workflow_hooks/can_be_merged.py --review-threads FAIL

AI Review

Summary

The PR registers the first argument of all three keyed SipHash functions as secret and adds a passing Fast Test regression for inline keys. Two remaining key-disclosure paths were reproduced with the PR-head binary, so the stated protection against readers of system.query_log is incomplete.

Findings

❌ Blockers

  • src/Functions/FunctionsHashingMisc.cpp:15 (inline finding): A WITH alias leaves the key in logged query text. WITH (1311768467463790320::UInt64, 18364758544493064720::UInt64) AS k SELECT sipHash64Keyed(k, number) FROM numbers(1) hides the reference passed to the function, but preserves both literals in system.query_log.query. Mask the originating definition in the logging representation; the same gap applies to all three registrations.
  • src/Functions/FunctionsHashingMisc.cpp:78 (inline finding): Stored keys remain visible in index diagnostics and exception logs. For a populated MergeTree table ordered by sipHash64Keyed((1311768467463790320, 18364758544493064720), x), SELECT * FROM t SETTINGS force_primary_key = 1 records both values in the INDEX_NOT_USED exception, including system.query_log.exception and the server log. The raw names are joined at src/Processors/QueryPlan/ReadFromMergeTree.cpp:4168. EXPLAIN indexes = 1 SELECT * FROM t WHERE x = 1 also prints the key, although SHOW CREATE TABLE correctly hides it. Render these stored expressions with secret-aware formatting.
Tests
  • ⚠️ Extend regression coverage to keys supplied through WITH aliases and to stored keyed expressions rendered in system.query_log.exception and EXPLAIN index diagnostics. The existing inline-key test passes but does not exercise these leaks.
Final Verdict

Status: ❌ Block

Close the alias-definition and index-diagnostic disclosure paths and add focused regression coverage.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Nov 23, 2026
@rschu1ze rschu1ze added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Nov 23, 2026
Comment thread src/Functions/FunctionsHashingMisc.cpp Resolved
Comment thread src/Functions/FunctionsHashingMisc.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 5b350ae69 with master 809ae9786 (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.

Object file sizes

4 object files changed (+84.94 KiB total), 0 added.

Object file Master PR Δ
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/FunctionsHashingMisc.cpp.o 5.83 MiB 5.92 MiB +84.95 KiB (+1.42%)

716 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

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

Job report

@clickhouse-gh clickhouse-gh Bot added the comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... label Nov 23, 2026
@rschu1ze

Copy link
Copy Markdown
Member Author

@clickhouse-gh Check again

@rschu1ze
rschu1ze added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit e36a738 Nov 23, 2026
198 of 200 checks passed
@rschu1ze
rschu1ze deleted the mask-keyed-siphash branch November 23, 2026 21:23
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Nov 23, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Nov 23, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Nov 23, 2026
Backport #133828 to 26.10: Mask the key of keyed SipHash functions in logged queries
rschu1ze added a commit that referenced this pull request Nov 24, 2026
Backport #133828 to 26.11: Mask the key of keyed SipHash functions in logged queries
clickhouse-gh Bot added a commit that referenced this pull request Nov 24, 2026
Backport #133828 to 26.8: Mask the key of keyed SipHash functions in logged queries
clickhouse-gh Bot added a commit that referenced this pull request Nov 24, 2026
Backport #133828 to 26.9: Mask the key of keyed SipHash functions in logged queries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-regular-function Regular scalar functions: string processing, data conversion, arithmetic, math, comparison, condi... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default 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.

4 participants