Repository navigation
Keep the valueless SETTINGS form out of the AST JSON round trip and secret detection - #112902
Conversation
`SETTINGS name` with no value is a shorthand for `= true` and is rejected for
a setting whose type is not `Bool`. Two paths sidestepped that rule.
`ASTSetQuery::writeJSON` did not serialize `SettingChange::shorthand` and
`readJSON` did not restore it, so the `clickhouse_json` dialect reconstructed
the valueless form as an explicit `name = true`, which is accepted for a
setting of any type: `parseQueryToJSON('SELECT 1 SETTINGS max_threads')`
round-tripped into a query that ran with `max_threads = 1` instead of failing
with `TYPE_MISMATCH`. The flag is now written and read back, and a payload
pairing it with anything other than `true` is rejected, so it cannot be used
to hide a real value - a secret one in particular - from `formatImpl` and from
`hasSecretParts`, both of which skip the value of a valueless setting.
`ASTSetQuery::hasSecretParts` read the value of
`format_avro_schema_registry_url` with `safeGet<String>`. `executeQueryImpl`
masks the query for logging before any settings validation runs, so a valueless
setting reached it as Bool `true` and
`SELECT * FROM (SELECT 1 SETTINGS format_avro_schema_registry_url)` reported
`BAD_GET` instead of the intended `TYPE_MISMATCH`. A valueless setting is now
skipped there as well.
Follow-up to the review comments left on
#112067
|
Workflow [PR], commit [4eaa220] Summary: ✅
AI ReviewSummaryThis PR preserves Findings❌ Blockers
Tests
Final Verdict
|
…time The `BAD_ARGUMENTS` rejection for a `shorthand` flag paired with a value the parser would never produce ran inside `IAST::createFromJSON`, before `executeQueryImpl` has an AST to mask with, so it sent the raw JSON text - the value included - down the unmasked `wipeSensitiveDataAndCutToLength` logging path. The value is kept instead: `hasSecretParts` can then still see it and `formatImpl` can still hide it, and `checkShorthandChange` rejects the setting itself once masked logging is available. The `TYPE_MISMATCH` is unchanged. `hasSecretParts` and `formatImpl` now read the value of `format_avro_schema_registry_url` with `tryGet<String>` rather than being guarded on `shorthand`. That covers the valueless form and every other `Field` type the AST JSON path can carry, so neither one can report `BAD_GET` in place of the setting's own error, and a crafted value that really is a String is still detected and masked rather than skipped.
|
🕵 Addressed in The blocker is right that the rejection ran inside Instead of guarding on One correction on the premise, though: the raw-JSON logging leak is not introduced here. A payload with no The plaintext password is in That is a separate pre-existing bug — it also corrupts ordinary string literals ( |
The test transported the JSON payloads through `TSV`, which escapes the backslash of the `\/` that `writeJSONString` emits for a `/`. The payload the test actually executed therefore carried a doubled backslash, so its URL was not a URL any more and could not have been masked whatever the code did. Captured with `FORMAT TSVRaw` instead. With faithful transport the crafted payload can be checked for what it is meant to check: executed over HTTP, so the rejection happens server-side, the `ExceptionBeforeStart` row in `system.query_log` is the masked AST (`SELECT 1 SETTINGS format_avro_schema_registry_url`, value omitted) rather than the raw JSON text, and it contains no password.
|
🕵 Correction to my previous comment: the "pre-existing raw-JSON leak" I described does not exist. I had captured the JSON payloads through So the blocker was right on its own terms, and the fix in
With the rejection still in place the second row would have been the raw JSON text with
|
… `query_log` read The `various` sub-check requires every `system.query_log` query to be scoped with `current_database = currentDatabase()`, and a `SYSTEM FLUSH LOGS` after a `curl` request to sit in a retry loop, because the HTTP response can return before the log entry is written (#84364).
| /// so throwing would send the raw JSON text - the value included - down the unmasked | ||
| /// `wipeSensitiveDataAndCutToLength` logging path. The value is kept instead, so | ||
| /// `hasSecretParts` can still see it and `formatImpl` can still hide it, and | ||
| /// `checkShorthandChange` then rejects the setting itself once logging is safe. |
There was a problem hiding this comment.
checkShorthandChange only verifies that a shorthand setting's type is Bool (BaseSettings.h:444-452); it does not require the carried value to still be true. With the current code, a payload like {"name":"optimize_move_to_prewhere","shorthand":true,"value":{"field_type":"Bool","value":false}} is accepted and applies false, while formatImpl drops the value for every shorthand change (ASTSetQuery.cpp:103-107).
That means formatQueryFromJSON, masked query logging, and any other formatter built on ASTSetQuery will render SETTINGS optimize_move_to_prewhere even though execution saw = false, so the "hide a real value behind the shorthand flag" bypass is still present for Bool settings. Please validate shorthand => value == true at the first post-deserialization point where masked logging is available (or make checkShorthandChange enforce it too).
There was a problem hiding this comment.
🕵 Confirmed and fixed in #113025.
BaseSettings::checkShorthandChange now also requires the carried value to be Bool true, after the existing type check (so a non-Bool setting still reports TYPE_MISMATCH). In addition, ASTSetQuery::formatImpl elides the value only when it really is true, so formatQueryFromJSON and the masked logging path can no longer render a bare setting name for a change that carries something else - the value is printed through the secret-masking path in the window before the change is rejected. New test 04691_shorthand_setting_value_mismatch.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 20/22 (90.91%) · Uncovered code |
…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: ClickHouse#112902
Follow-up to the two unresolved review comments on #112067 (merged as
a208bbb94ab).SETTINGS namewith no value is a shorthand for= true, and #112067 made it an error for a setting whose type is notBool. Two paths sidestepped that rule.The AST JSON round trip dropped the flag.
ASTSetQuery::writeJSONdid not serializeSettingChange::shorthandandreadJSONdid not restore it, so theclickhouse_jsondialect reconstructed the valueless form as an explicitname = true, which is accepted for a setting of any type:The flag is now written and read back. A payload pairing it with anything other than
trueis rejected withBAD_ARGUMENTS: bothformatImplandhasSecretPartsskip the value of a valueless setting, so without that check the flag could be used to hide a real value - a secret one in particular - from formatting and from the query log.hasSecretPartsread the value as a String.executeQueryImplmasks the query for logging before any settings validation runs, so a valuelessformat_avro_schema_registry_urlreachedsafeGet<String>as Booltrue:It now reports the intended
TYPE_MISMATCH. A valueless setting carries Booltrueand can never be secret.New test
04665_valueless_setting_ast_json_and_secret_parts.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Related: #112067