Skip to content

Reject a valueless SETTINGS form that carries a value other than true - #113025

Merged
alexey-milovidov merged 2 commits into
masterfrom
fix-shorthand-setting-value-mismatch
Aug 3, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
fix-shorthand-setting-value-mismatch

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 2, 2026 •

Copy link
Copy Markdown
Member

The valueless SETTINGS name form stands for name = true. SettingChange::shorthand records that it was written without a value, and the parser always pairs the flag with Bool true — but the AST JSON dialect can pair it with any other value, and BaseSettings::checkShorthandChange only verified that the setting's type is Bool.

So a payload like

{"name":"optimize_move_to_prewhere","shorthand":true,"value":{"field_type":"Bool","value":false}}

was accepted and executed with false, while ASTSetQuery::formatImpl elided the value for every shorthand change — formatQueryFromJSON, system.query_log and every other formatter rendered SETTINGS optimize_move_to_prewhere, under-reporting what actually ran.

Two changes:

  • checkShorthandChange now also requires the carried value to be Bool true. It runs after the settings type check, so a non-Bool setting still reports TYPE_MISMATCH, and it is the first point after deserialization where an exception is logged with the AST masked rather than with the raw JSON text.
  • formatImpl elides the value only when it really is true, so a formatter can never print a bare setting name for a change that carries something else. In the window before the change is rejected, the value of a crafted payload is printed through the secret-masking path, so a password is still hidden in system.query_log.

The reference of 04665_valueless_setting_ast_json_and_secret_parts is updated for the second change: the crafted payload now formats with its value, masked (http://user:[HIDDEN]@localhost) on the logging path and shown by formatQueryFromJSON, which formats with show_secrets = true exactly like formatQuerySingleLine in the line below it.

Follow-up to the AI review finding on #112902.

Related: #112902

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 to CHANGELOG.md):

Reject a SETTINGS change marked as written without a value when it carries a value other than true, and never elide the value of such a change when formatting a query. Previously a crafted AST JSON payload could execute a Bool setting with false while system.query_log and formatQueryFromJSON showed the valueless form.

Version info

  • Merged into: 26.8.1.708 (included in 26.8 and later)

…rue`

`SettingChange::shorthand` records that a setting was written as `SETTINGS name`
with no value, which stands for `name = true`. The parser always pairs the flag
with Bool `true`, but the AST JSON dialect can pair it with anything, and
`BaseSettings::checkShorthandChange` only verified that the setting's type is
`Bool`. A payload such as

    {"name":"optimize_move_to_prewhere","shorthand":true,
     "value":{"field_type":"Bool","value":false}}

was therefore accepted and executed with `false`, while `ASTSetQuery::formatImpl`
elided the value for every shorthand change - so `formatQueryFromJSON`,
`system.query_log` and every other formatter rendered
`SETTINGS optimize_move_to_prewhere`, under-reporting what actually ran.

`checkShorthandChange` now also requires the carried value to be Bool `true`.
It runs after the settings type check, so a non-`Bool` setting still reports
`TYPE_MISMATCH`, and it is the first point after deserialization where an
exception is logged with the AST masked rather than with the raw JSON text.

`formatImpl` now elides the value only when it really is `true`, so a formatter
can never print a bare setting name for a change that carries something else -
the value of a crafted payload is printed, through the secret-masking path, in
the window before the change is rejected.

Related: #112902
@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [6040924]

Summary: ✅


AI Review

Summary

This PR tightens ASTSetQuery handling so a shorthand SETTINGS name form is only elided when it actually carries true, and it adds a BaseSettings-level rejection for crafted AST JSON payloads that mark a setting as valueless while carrying another value. The formatter side looks correct, but the rejection side is incomplete: several settings surfaces still read ASTSetQuery::changes directly and can execute the smuggled value.

Findings

⚠️ Majors

  • [src/Core/BaseSettings.h:455] The new value == true check only runs for settings that go through BaseSettings. Raw ASTSetQuery consumers such as src/Storages/StorageJoin.cpp:421-444 and src/Interpreters/InterpreterExplainQuery.cpp:623-642 still ignore the carried-value mismatch, so a clickhouse_json payload can continue to execute an impossible shorthand setting there instead of being rejected. That closes the logging/formatting divergence, but not the promised semantic rejection across all reachable settings surfaces.
Final Verdict

⚠️ Needs another pass before merge: the new invariant is enforced too low in the stack, so malformed shorthand settings are still accepted in current code paths that bypass BaseSettings.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.50% 86.40% -0.10%
Functions 91.90% 91.90% +0.00%
Branches 78.70% 78.60% -0.10%

Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 2, 2026
…t query it

The check requires every stateless test naming `system.query_log` to filter on
`current_database = currentDatabase()`; here the name only appeared in a comment.
Comment thread src/Core/BaseSettings.h
if (std::string_view type = getTypeName(change.name); type != "Bool")
BaseSettingsHelpers::throwValuelessSettingIsNotBool(change.name, type);

/// The type alone is not enough. The parser writes Bool `true` for the valueless form, but a

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still leaves non-BaseSettings settings surfaces bypassable. A clickhouse_json CREATE TABLE ... ENGINE = Join ... SETTINGS persistent = false payload with "shorthand":true reaches StorageJoin.cpp:421-444, where we only whitelist Bool setting names and then assign setting.value unchanged, so it still executes persistent = false instead of rejecting the impossible shorthand. InterpreterExplainQuery.cpp:623-642 has the same shape for EXPLAIN settings. Because the PR promises to reject a change marked as valueless whenever it carries something else, this invariant probably needs a shared validation step for every raw ASTSetQuery reader, not just BaseSettings.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much less of a problem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵 Confirmed: the Join engine executed persistent = false for a payload claiming the valueless form, and EXPLAIN settings never consult a BaseSettings schema at all. Follow-up #113192 adds the shared validation step: the parser-impossible shape (shorthand paired with a value other than true) is now rejected once for the whole query tree in executeQueryImpl for ASTs deserialized from the JSON dialect, after query_for_logging is prepared so the exception is logged with the AST masked. This covers every raw SettingsChanges reader instead of patching each one.

@clickhouse-gh

clickhouse-gh Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 604092419 with master 90042b2dc (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 4b3181f56; compile times per translation unit against the most recent warmup build that recompiled it).

⚠️ Significant changes: object file sizes, slowest function optimization changes (thinlto).

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 685.41 MiB 682.31 MiB -3.10 MiB (-0.45%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Object file sizes ⚠️

309 object files changed (-39.66 MiB total), 1 added, 685 removed.

Object file Master PR Δ
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/cht… 960.56 KiB removed -960.56 KiB (-100.00%)
src/Common/ZooKeeper/CMakeFiles/clickhouse_common_zookeeper_no_log.dir/ZooKeeperImpl.cpp.o 806.39 KiB removed -806.39 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/server/server.cc.o 612.22 KiB removed -612.22 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/rls/rls.cc.o 611.36 KiB removed -611.36 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel_filt… 548.04 KiB removed -548.04 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/client_channel.cc.o 525.46 KiB removed -525.46 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_interceptor.c… 518.85 KiB removed -518.85 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/lib/channel/promise_based_filter.c… 482.91 KiB removed -482.91 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/load_balancing/grpclb/grpclb.cc.o 434.97 KiB removed -434.97 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/client_call.cc.o 433.89 KiB removed -433.89 KiB (-100.00%)
src/CMakeFiles/dbms.dir/Databases/DatabaseURL.cpp.o new 400.85 KiB +400.85 KiB
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/call/server_call.cc.o 391.29 KiB removed -391.29 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc++_unsecure.dir/__/grpc/src/cpp/server/server_cc.cc.o 384.88 KiB removed -384.88 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/client_channel/retry_filter_legacy… 369.55 KiB removed -369.55 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/chttp2/transport/wri… 349.81 KiB removed -349.81 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_grpc_utils.dir/__/google-cloud-cpp/googl… 346.93 KiB removed -346.93 KiB (-100.00%)
contrib/grpc-cmake/CMakeFiles/grpc_unsecure.dir/__/grpc/src/core/ext/transport/inproc/legacy_inproc… 345.35 KiB removed -345.35 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_longrunning_operations_protos.dir/google… 339.33 KiB removed -339.33 KiB (-100.00%)
contrib/google-cloud-cpp-cmake/CMakeFiles/google_cloud_cpp_iam_credentials_v1_iamcredentials_protos… 334.24 KiB removed -334.24 KiB (-100.00%)
contrib/google-protobuf-cmake/CMakeFiles/_libprotobuf-lite.dir/__/google-protobuf/src/google/protob… 316.58 KiB removed -316.58 KiB (-100.00%)
Slowest function optimization changes (ThinLTO) ⚠️

Median per-function time ratio to the master baseline is ×1.27 (different machine and build flags); deltas below are relative to that ratio.

Binary Function Master PR Δ vs median
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.2319240611476442113] new 18.8 s +18.8 s
programs/clickhouse-keeper DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.6969868754578406721] 8.5 s gone -10.8 s (-100%)
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.6969868754578406721] 8.0 s gone -10.1 s (-100%)
programs/clickhouse DB::SettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.2319240611476442113] new 7.2 s +7.2 s
programs/clickhouse-keeper DB::registerFunctionConversion(DB::FunctionFactory&) 6.9 s 15.5 s +6.8 s (+78%)
programs/clickhouse-keeper _GLOBAL__sub_I_TargetLibraryInfo.cpp 5.9 s 12.0 s +4.6 s (+62%)
programs/clickhouse DB::Parquet::writeColumnChunkBody(DB::Parquet::ColumnChunkWriteState&, DB::Parquet::WriteOptions co… 5.2 s 3.7 s -2.9 s (-44%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.41530897155626… new 2.7 s +2.7 s
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.38157299961… new 2.6 s +2.6 s
programs/clickhouse DB::getSettingsChangesHistory()::$_0::operator()() const 4.3 s 3.0 s -2.5 s (-45%)
programs/clickhouse DB::attachSystemTablesServer(std::__1::shared_ptr<DB::Context const>, DB::IDatabase&, bool, bool) 4.3 s 3.1 s -2.4 s (-43%)
programs/clickhouse DB::Aggregator::writeToTemporaryFile(DB::AggregatedDataVariants&, unsigned long) const 3.4 s 1.9 s -2.4 s (-55%)
programs/clickhouse-keeper DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12822858084705… 1.8 s gone -2.3 s (-100%)
programs/clickhouse-keeper _GLOBAL__sub_I_sqid.cpp 1.7 s 4.4 s +2.3 s (+105%)
programs/clickhouse DB::ServerSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.12822858084705… 1.7 s gone -2.2 s (-100%)
programs/clickhouse-keeper _ZN2DB18FunctionArrayIndexINS_16CountEqualActionENS_14NameCountEqualEE15executeIntegralIJDutjmDB8_s… 1.9 s 4.6 s +2.2 s (+88%)
programs/clickhouse-keeper DB::MergeTreeSettingsTraits::Accessor::instance()::$_0::operator()() const [clone .llvm.10544783980… 1.6 s gone -2.0 s (-100%)
Compile time of recompiled translation units

43 translation units recompiled, 174 s compile time in total, 6 of them have a recent master baseline.

Translation units without a recent master baseline:

  • src/Core/ServerSettings.cpp: 14.6 s
  • src/Storages/StorageJoin.cpp: 11.8 s
  • src/Storages/MergeTree/MergeTreeSettings.cpp: 10.7 s
  • src/Core/Settings.cpp: 9.8 s
  • src/Storages/ObjectStorageQueue/registerQueueStorage.cpp: 9.5 s
  • src/Storages/ObjectStorageQueue/ObjectStorageQueueSettings.cpp: 9.1 s
  • src/Storages/ObjectStorage/StorageObjectStorageSettings.cpp: 6.9 s
Symbol sizes

No symbol data for the master baseline yet (it is collected for release builds only since this check was introduced); the comparison will activate once master catches up.

Job report

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright.

@alexey-milovidov alexey-milovidov self-assigned this Aug 3, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Aug 3, 2026
Merged via the queue into master with commit 74423a1 Aug 3, 2026
180 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-shorthand-setting-value-mismatch branch August 3, 2026 20:26
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default 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.

2 participants