Repository navigation
Cherry pick #125495 to 26.3: Fix row-policy bypass via client-supplied scalar overriding a policy's scalar subquery - #127313
Merged
Conversation
…uery cache A row policy whose USING expression contains a scalar subquery, e.g. `has((SELECT [2]), tenant_id)`, is resolved through the analyzer's scalar-subquery cache. That cache lives in `Context::scalars`, the same map into which `TCPHandler::processData` writes whatever a client sends in a `Scalar` packet (the `clickhouse-client --external ... --scalar` feature). The map has no provenance marker and the analyzer keys its lookup on the subquery's query-tree hash, so an authenticated user who holds only `SELECT` on the table can name a client scalar with that hash and forge the result of `(SELECT [2])`, replacing the row policy's predicate with an attacker-chosen array and reading every row. Track which entries of `Context::scalars` were supplied by the client (`addClientScalar`) and add `hasComputedScalar`, which reports only server-computed entries. The analyzer's scalar-subquery cache lookup (new and old analyzer) now uses `hasComputedScalar`, so a forged client scalar can no longer stand in for a subquery result and the subquery is executed. Explicit readers - `__getScalar`, `_shard_num`, and forwarding scalars to shards - keep reading client-supplied entries through `getScalar`/`hasScalar`/`getScalars`, so `--external ... --scalar` and distributed queries (which ship scalars over the same packet, including in the default no-`<secret>` configuration) are unaffected. Co-authored-by: yakov <[email protected]>
The test injects a forged `Scalar` packet named with the policy subquery's query-tree hash and checks the row policy still holds, that an explicit `__getScalar` reference to a client scalar keeps working, and that scalars shipped to shards in a distributed query still resolve. Co-authored-by: yakov <[email protected]>
The previous fix tracked which `Context::scalars` were client-supplied in a
separate `client_supplied_scalars` set kept in sync with the map by hand. That
left provenance in a second container that a future writer could forget to
update, silently reopening the bypass.
Store the origin with the scalar instead: `Context::scalars` now maps to a
`ScalarEntry { Block block; bool from_client; }`. `addScalar` writes
`from_client = false` (and so a server-computed value still overrides a
client-supplied one of the same name), `addClientScalar` writes
`from_client = true`, and `hasComputedScalar` reports an entry only when it is
not client-supplied. `getScalars` keeps returning a plain `Scalars`, so shard
forwarding and every other reader are unchanged; the origin is re-derived on a
shard when the forwarded scalar arrives through `addClientScalar`.
No behavior change - the analyzer's scalar-subquery cache still ignores
client-supplied scalars, so the row-policy bypass stays fixed.
Co-authored-by: yakov <[email protected]>
…ar-bypass-2579 Fix row-policy bypass via client-supplied scalar overriding a policy's scalar subquery
|
|
robot-clickhouse
force-pushed
the
backport/26.3/125495
branch
from
October 22, 2026 17:22
e2d92fe to
f8fe169
Compare
Contributor
|
Dear @pufit, @yakov-olkhovskiy, this cherry-pick PR has not been updated for 3d0h0m15s. Please resolve the conflicts to backport #125495, or close this PR if the backport is no longer needed. This PR will be automatically closed after 7 days of inactivity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Original pull-request #125495
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job