Skip to content

Reject CR/LF in outgoing HTTP request lines and headers - #124905

Merged
alexey-milovidov merged 21 commits into
ClickHouse:masterfrom
Algunenano:bigquery-header-crlf
Oct 16, 2026
Merged

alexey-milovidov merged 21 commits into
ClickHouse:masterfrom
Algunenano:bigquery-header-crlf

Conversation

@Algunenano

@Algunenano Algunenano commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Values that end up in outgoing HTTP requests could contain CR or LF, which let a user inject headers or a whole second request into the connection: BigQuery billing_project/access_token, YTsaurus oauth_token, the forwarded tracestate in url, DataLake catalog auth headers (REST/OneLake/Horizon OAuth tokens, BigLake x-goog-user-project, Paimon DLF, S3 Tables SigV4), GCP OAuth tokens, AI provider API keys, the S3 storage class, and headers built by the AWS SDK (SigV4 access key).

HTTPRequest::write in Poco now refuses to write a request line or header containing CR or LF, so no client can send one. On top of that, the user-facing sources are validated early (with HTTPHeaderFilter::checkHeaders where a context is available) to give a clear error and enforce http_forbid_headers. The Avro schema registry now keeps the registry URL path percent-encoded when registering a schema.

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

Reject CR and LF characters in values sent as HTTP headers or in the request line of outgoing HTTP requests (BigQuery, YTsaurus, url, DataLake catalogs, GCP OAuth, AI functions, S3 storage class), which could be used to inject headers or additional requests.


Workflow [PR]
Sync PR [sync-upstream/pr/124905]

Version info

  • Merged into: 26.11.1.108-master (included in 26.11 and later)
  • Backported to: 26.10.2.7, 26.9.21.9, 26.8.30.8, 26.7.35.12, 26.3.55.2

Algunenano and others added 11 commits October 9, 2026 11:32
`billing_project` and `access_token` were sent as HTTP headers unchecked, so CR/LF could inject headers or a second request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The token was sent in the `Authorization` header unchecked, so CR/LF could inject headers or a second request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A value with CR/LF in the request line or a header could inject headers or a second request. This covers every client, including headers built by the AWS and Azure SDKs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…Filter`

The `tracestate` forwarded by `url`, Paimon DLF signing headers, REST catalog OAuth tokens, the BigLake `x-goog-user-project` and S3 Tables SigV4 headers were sent unchecked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… schema

The registration request used the decoded path of `format_avro_schema_registry_url`, so an encoded CR/LF reached the request line.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tokens from the metadata service or a token endpoint were sent as `Authorization: Bearer` unchecked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The `api_key` of the named collection was sent as an HTTP header unchecked.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
An unknown storage class is sent as is in `x-amz-storage-class`, and `BACKUP` and `s3_validate_request_settings = 0` skip validation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… too

The early check ran only for `mode <= CREATE`, so a user `ATTACH TABLE ... UUID ... ENGINE = ...` skipped it. Use `isReplayedTableDefinition`, which skips only stored definitions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [294933f]

Summary: ✅


AI Review

Summary

The PR rejects CR/LF in outgoing HTTP request lines and headers, validates credential and tracing headers against HTTPHeaderFilter, and encodes the Avro schema-registration path. No actionable findings remain at head 294933f5927f46cab3bea146e52e00205bd80084. The previously reported serializer bypass is fixed in both overloads of HTTPRequest::write; its bot-authored thread has been resolved.

Missing context / blind spots
  • ⚠️ Full server regression results for the current head are pending. A local harness using the exact validation and serializer bodies passed 90 rejection cases and six valid-input cases across both overloads, but used stand-in message/header containers and exercised no network or server. Running the added stateless tests 05345–05350 against the current head closes this runtime-validation gap.
Final Verdict

✅ Approve. No remaining review changes requested; full server CI validation remains pending.

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Oct 9, 2026
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Oct 9, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 294933f59 with master f9a06cc67 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of e2e3e0954; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Object file sizes

27 object files changed (+66.96 KiB total), 0 added.

Object file Master PR Δ
src/Functions/CMakeFiles/clickhouse_functions_obj.dir/AI/AnthropicProvider.cpp.o 730.49 KiB 749.12 KiB +18.63 KiB (+2.55%)

719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only clickhouse-bundle) and not compared.

Compile time of recompiled translation units

94 translation units recompiled, 870 s compile time in total, 94 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +36.4 s (+4%) in total before that adjustment.

Job report

Comment thread base/poco/Net/src/HTTPRequest.cpp Resolved
Comment thread src/Functions/AI/IAIProvider.cpp Resolved
Algunenano and others added 5 commits October 13, 2026 09:53
The `Authorization`, `x-api-key` and `anthropic-version` headers sent by AI functions bypassed `http_forbid_headers`. `createAIProvider` now validates the provider's headers with the context's filter, which also rejects CR/LF in their values.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`HTTPRequest::write` now also checks the version in the request line. The Avro schema registry test raises the registry timeouts, because the default of 1 second is too short under TSan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment thread src/IO/S3/PocoHTTPClient.cpp Resolved
…uth` S3 client

The `gcp_oauth` client adds `Authorization` itself, so `http_forbid_headers` was bypassed. Check it when the client is created for tables, disks and backups.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Comment thread base/poco/Net/src/HTTPRequest.cpp Resolved
@clickgapai

Copy link
Copy Markdown
Contributor

@Algunenano @alexey-milovidov — ClickGap found the following in this PR:

Close anything that's wrong or already addressed.

clickhouse-gh Bot added a commit that referenced this pull request Oct 16, 2026
Backport #124905 to 26.10: Reject CR/LF in outgoing HTTP request lines and headers
alexey-milovidov added a commit that referenced this pull request Oct 17, 2026
Adaptations to 26.9:
- `HTTPHeaderFilter::checkHeaders` does not exist here; use `checkAndNormalizeHeaders`, which also rejects CR and LF.
- `isReplayedTableDefinition` does not exist here; use `isFreshTableDefinition` and `isRecoveryFromStoredMetadata` in `StorageBigQuery` and `StorageYTsaurus`.
- `Poco::Net::HTTPRequest::write(std::string &)` does not exist here, so only `write(std::ostream &)` gets the check.
- The AI providers keep `AIRequest` and the `X-ClickHouse-AI-Function` header of 26.9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Oct 17, 2026
Adaptations to 26.8:
- `HTTPHeaderFilter::checkHeaders` does not exist here; use `checkAndNormalizeHeaders`, which also rejects CR and LF.
- `isReplayedTableDefinition` does not exist here; use `isFreshTableDefinition` and `isRecoveryFromStoredMetadata` in `StorageBigQuery` and `StorageYTsaurus`.
- `Poco::Net::HTTPRequest::write(std::string &)` does not exist here, so only `write(std::ostream &)` gets the check.
- The AI providers keep the `call` signature and the `X-ClickHouse-AI-Function` header of 26.8.
- `S3::getStorageClassForName` is added to `Requests.cpp` together with the declaration of `INVALID_SETTING_VALUE`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
Cherry pick #124905 to 26.8: Reject CR/LF in outgoing HTTP request lines and headers
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
Cherry pick #124905 to 26.9: Reject CR/LF in outgoing HTTP request lines and headers
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
alexey-milovidov added a commit that referenced this pull request Oct 17, 2026
Adaptations to 26.7:
- `BigQuery`, `S3TablesCatalog` and `aiSimilarity` do not exist here: their changes and the test `05345_bigquery_header_injection` are dropped.
- `HTTPHeaderFilter::checkHeaders` does not exist here; use `checkAndNormalizeHeaders`, which also rejects CR and LF.
- `isReplayedTableDefinition` does not exist here; use `isFreshTableDefinition` and `isRecoveryFromStoredMetadata` in `StorageYTsaurus`.
- `Poco::Net::HTTPRequest::write(std::string &)` does not exist here, so only `write(std::ostream &)` gets the check.
- The AI providers keep the `call` signature and the `X-ClickHouse-AI-Function` header of 26.7.
- `S3::getStorageClassForName` is added to `Requests.cpp` together with the declaration of `INVALID_SETTING_VALUE`.
- `checkGCPOAuthAccessToken` is added to the single `fetchGCPOAuthToken` of 26.7; `PaimonRestCatalog` checks the headers after `createAuthHeaders` without the bearer token validation absent here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
alexey-milovidov added a commit that referenced this pull request Oct 17, 2026
Adaptations to 26.3:
- `BigQuery`, `S3TablesCatalog`, the AI functions and the AvroConfluent schema registration do not exist here:
  their changes and the tests `05345_bigquery_header_injection`, `05349_avro_confluent_registry_url_crlf`
  and `05350_ai_functions_api_key_crlf` are dropped.
- `HTTPHeaderFilter::checkHeaders` does not exist here; use `checkAndNormalizeHeaders`, which also rejects CR and LF.
- `isReplayedTableDefinition` does not exist here; use `isFreshTableDefinition` and `isRecoveryFromStoredMetadata` in `StorageYTsaurus`.
- `Poco::Net::HTTPRequest::write(std::string &)` does not exist here, so only `write(std::ostream &)` gets the check.
- `S3::getStorageClassForName` is added to `Requests.cpp` together with the declaration of `INVALID_SETTING_VALUE`;
  `WriteBufferFromS3::createMultipartUpload` does not set the storage class here, so only the other call sites use it.
- The `gcp_oauth` header check in `BackupIO_S3.cpp` and `diskSettings.cpp` is added without the surrounding
  code of newer versions (shared client cache, implicit credentials restriction).
- `checkGCPOAuthAccessToken` is added to the single `fetchGCPOAuthToken` of 26.3; `PaimonRestCatalog` checks the
  headers after `createAuthHeaders` without the bearer token validation absent here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robot-ch-test-poll3 added a commit that referenced this pull request Oct 17, 2026
Cherry pick #124905 to 26.3: Reject CR/LF in outgoing HTTP request lines and headers
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
robot-ch-test-poll3 added a commit that referenced this pull request Oct 17, 2026
Cherry pick #124905 to 26.7: Reject CR/LF in outgoing HTTP request lines and headers
robot-clickhouse added a commit that referenced this pull request Oct 17, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 17, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 17, 2026
Backport #124905 to 26.8: Reject CR/LF in outgoing HTTP request lines and headers
clickhouse-gh Bot added a commit that referenced this pull request Oct 17, 2026
Backport #124905 to 26.9: Reject CR/LF in outgoing HTTP request lines and headers
alexey-milovidov added a commit that referenced this pull request Oct 17, 2026
Backport #124905 to 26.3: Reject CR/LF in outgoing HTTP request lines and headers
Algunenano added a commit that referenced this pull request Oct 20, 2026
Backport #124905 to 26.7: Reject CR/LF in outgoing HTTP request lines and headers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

5 participants