Repository navigation
Do not let the request body extend the query of a custom HTTP handler - #126642
Conversation
A request to a SQL-defined handler whose query uses `_request_body` could pass `param__request_body` in the URL. The body was then left unread and appended to the handler's query text, so a body such as `UNION ALL SELECT 1+1` extended the handler's SQL. Now the body is appended to the query of a SQL-defined handler only as the data of an `INSERT` (or of the `input` table function), and `_request_body` cannot be passed in the URL of a predefined or SQL-defined handler. ClickHouse/clickhouse-private#76671 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Preview deployment for your docs. Learn more about Mintlify Previews.
|
|
Workflow [PR], commit [38724bb] Summary: ✅
AI ReviewSummaryThis PR prevents HTTP request bodies from extending the stored SQL of Missing context / blind spots
Final VerdictStatus: ✅ Approve |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units24 translation units recompiled, 132 s compile time in total, 24 of them have a recent master baseline. |
…iguration-defined handler A named capture group of `url_regexp` or `headers_regexp` of a `predefined_query_handler` could bind `_request_body`. The body was then left unread and appended to the handler's query text, so a body such as `UNION ALL SELECT 1+1` still extended the handler's SQL. Such a capture is now rejected with `BAD_ARGUMENTS` whenever the handler appends the body to its query. SQL-defined handlers append the body only to an `INSERT`, which cannot use `_request_body`, so a `URL REGEXP` capture may still bind it there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…figuration-defined handler Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ad the body A `CREATE HANDLER` whose `URL REGEXP` has a named capture group `_request_body` binds the parameter from the URL, so the handler never reads the request body for it. But `consumes_request_body` was still derived from the query using `_request_body`, so such a handler was rejected with `GET`, and every request without `Content-Length` was answered with `411 Length Required`. Drop a captured `_request_body` from the parameters bound by the handler layer in `makeSQLDefinedHandler`, so the body-consumption contract matches the execution, and the body is never read for it. Rejecting such handlers at creation instead would make already stored handlers fail to load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rom a `URL REGEXP` capture A SQL-defined handler binding `_request_body` from a named capture group of its `URL REGEXP` drops it from `receive_params`, so that the body is never read for it. That also removed the only signal `PredefinedQueryHandler::customizeQueryParam` used to reject `_request_body` passed in the URL query string: `?param__request_body=...` was silently ignored and `?_request_body=...` fell through to the generic path. Track separately whether the query uses `_request_body` (`uses_request_body_param`) and use it for the URL guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=126642&sha=3a5c6fbe4edac34e2bd50bfded3aa03db8ef8bb3&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20sequential%29 ( |
|
The fix is my open #127781 (a separate, test-only PR). The run here at |
Two remaining paths let the request body extend the SQL of a custom HTTP handler:
- A SQL-defined handler whose query takes the body as data but has no literal data
boundary, such as `INSERT INTO t SELECT x FROM input('x UInt64')` without `FORMAT`:
the body was concatenated to the query text before parsing, so a body like
`UNION ALL SELECT 99 FORMAT TSV` became part of the query. Now the query of a
SQL-defined handler that feeds the body to the query is parsed from the stored
text alone (`parse_query_from_initial_buffer`), and the body is only its data.
- A `_request_body` query parameter left in a named HTTP session by
`SET param__request_body = ...` made the handler skip reading the body. A
configuration-defined handler then appended the unread body to its query, and a
SQL-defined handler used the stale value. Such an inherited value is now dropped
by a handler using `_request_body`, so it is bound from the current request only.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `TabSeparated` output escapes single quotes, so use a body without them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕵 Thanks @groeneai. #127781 is merged, and I merged the latest master into this branch, so |
|
🕵 The remaining failures at
@groeneai, if any of these has no fix in progress yet, please investigate it and provide a fix in a separate PR. |
|
Status per line:
|
…es without rabbitmqctl `rabbitmqctl close_all_connections test` timed out after 300 s in 3 runs of `Integration tests (arm_binary, 2/4)` (master 524a0c2, ClickHouse#127389, ClickHouse#126642). The close never reached the broker: no `Closing connection ... because "test"` line in its log, and ClickHouse's AMQP connection stayed open for 5 minutes until the test dropped the database. The broker passed its `rabbitmq-diagnostics ping` healthcheck 29/29 times in each window, so a new CLI process again never got to its RPC, like the `list_queues` call before. Bounding the call and asking again does not fit here: the drop must happen while most of the backlog is still queued (`view_rows() < messages_num // 2`), which leaves about 9 s after the 500-row trigger at ~490 rows/s, and a timed-out `docker exec` leaves the CLI running in the container, where a late close would force a second reconnect. Close through the management API instead: `DELETE /api/connections/username/root` with `X-Reason: test` reaches the same `rabbit_networking:close_connection(Pid, "test")` for every connection of the broker's only user, synchronously before the 204 reply, and starts no CLI process. Validated: an injected never-returning close fails the unfixed test after 300 s with the CI error; without the DELETE the test fails waiting for the reconnect; the pre-ClickHouse#125105 binary still fails on the duplicates bound (9500, 9400); 50/50 runs pass with `204` (p50 0.1 s) and ClickHouse logs `CONNECTION_FORCED - test` then `Connection restored`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
|
|
🕵 Thanks @groeneai for the status. I merged the latest master ( |
|
🕵 The only failure at |
# Conflicts: # src/Server/HTTPHandler.cpp # src/Server/HTTPHandler.h
|
🕵 The only failure at |
Related: https://github.com/ClickHouse/clickhouse-private/issues/76671#issuecomment-6259244186
A request to a SQL-defined handler (
CREATE HANDLER) whose query uses{_request_body:String}could also passparam__request_bodyin the URL. The body was then left unread, and the HTTP layer appended it to the handler's query text, as it does for the default handler. So a body such asUNION ALL SELECT 1+1became part of the handler's SQL. No new privileges were gained, because the HTTP interface runs arbitrary queries anyway. But a custom handler is expected to run only its own query.This change does the following:
INSERT, or anINSERT ... SELECTreading frominput. Otherwise the body is never appended, including when_request_bodyis bound some other way, such as from aURL REGEXPcapture group._request_bodyin the URL (as_request_bodyorparam__request_body) to a predefined or SQL-defined handler now throws aBAD_ARGUMENTSexception. For a SQL-defined handler whoseURL REGEXPhas a named capture group_request_body, the parameter is bound from that capture and the body is never read for it, so such a handler may useGETand does not requireContent-Length.predefined_query_handlerrules, whose query is not analyzed and whose body is always appended, binding_request_bodyfrom a named capture group ofurl/headersregular expressions also throws aBAD_ARGUMENTSexception.INSERT ... SELECT ... FROM input(...)without a literalFORMAT._request_bodyleft in a named HTTP session (SET param__request_body = ...) is ignored by handlers using it: the parameter is bound from the current request only.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
The request body of a SQL-defined HTTP handler (
CREATE HANDLER) is appended to the handler's query only as the data of anINSERT, so it can never extend the handler's SQL. The_request_bodyquery parameter of custom HTTP handlers can no longer be passed in the URL.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/126642]
Version info
26.11.1.1560-master(included in26.11and later)