Repository navigation
Reject a valueless SETTINGS form that carries a value other than true - #113025
Conversation
…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
|
Workflow [PR], commit [6040924] Summary: ✅
AI ReviewSummaryThis PR tightens Findings
Final Verdict
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 12/12 (100.00%) · Uncovered code |
…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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is a much less of a problem.
There was a problem hiding this comment.
🕵 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.
Build profile diff (arm_release)Comparing Binary sizes
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
|
| 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 ssrc/Storages/StorageJoin.cpp: 11.8 ssrc/Storages/MergeTree/MergeTreeSettings.cpp: 10.7 ssrc/Core/Settings.cpp: 9.8 ssrc/Storages/ObjectStorageQueue/registerQueueStorage.cpp: 9.5 ssrc/Storages/ObjectStorageQueue/ObjectStorageQueueSettings.cpp: 9.1 ssrc/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.
The valueless
SETTINGS nameform stands forname = true.SettingChange::shorthandrecords that it was written without a value, and the parser always pairs the flag with Booltrue— but the AST JSON dialect can pair it with any other value, andBaseSettings::checkShorthandChangeonly verified that the setting's type isBool.So a payload like
{"name":"optimize_move_to_prewhere","shorthand":true,"value":{"field_type":"Bool","value":false}}was accepted and executed with
false, whileASTSetQuery::formatImplelided the value for every shorthand change —formatQueryFromJSON,system.query_logand every other formatter renderedSETTINGS optimize_move_to_prewhere, under-reporting what actually ran.Two changes:
checkShorthandChangenow also requires the carried value to be Booltrue. It runs after the settings type check, so a non-Boolsetting still reportsTYPE_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.formatImplelides the value only when it really istrue, 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 insystem.query_log.The reference of
04665_valueless_setting_ast_json_and_secret_partsis updated for the second change: the crafted payload now formats with its value, masked (http://user:[HIDDEN]@localhost) on the logging path and shown byformatQueryFromJSON, which formats withshow_secrets = trueexactly likeformatQuerySingleLinein the line below it.Follow-up to the AI review finding on #112902.
Related: #112902
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Reject a
SETTINGSchange marked as written without a value when it carries a value other thantrue, and never elide the value of such a change when formatting a query. Previously a crafted AST JSON payload could execute aBoolsetting withfalsewhilesystem.query_logandformatQueryFromJSONshowed the valueless form.Version info
26.8.1.708(included in26.8and later)