Skip to content

Reject invalid characters in HTTP header names - #118830

Merged
serxa merged 15 commits into
masterfrom
reject-colon-in-http-header-names
Sep 28, 2026
Merged

serxa merged 15 commits into
masterfrom
reject-colon-in-http-header-names

Conversation

@serxa

@serxa serxa commented Sep 8, 2026 •

Copy link
Copy Markdown
Member

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 invalid HTTP header names supplied to SQL-facing HTTP clients (the url table function and engine, HTTP dictionaries, S3/object storage, DataLake/REST catalogs). A header name must be a valid RFC 9110 token (letters, digits and !#$%&'*+-.^_`|~); any other byte — :, whitespace, control characters or separators such as / and = — is rejected. Such names could previously bypass the <http_forbid_headers> restriction.

Documentation entry for user-facing changes

Follow-up to #115510, which rejected bare CR/LF in header names and values.

A header name is now required to be an RFC 9110 token: a non-empty sequence of tchar bytes (letters, digits and !#$%&'*+-.^_`|~). Any other byte is rejected, including :, whitespace, control characters and separators such as / or =. A non-token name may not match <http_forbid_headers> in ClickHouse while a downstream server still parses a forbidden header out of it — for example Cookie:x is not equal to Cookie, yet a peer can read a Cookie header from it — so it could bypass the restriction. Previously such a name was normalized (whitespace and control characters stripped) rather than rejected, which left bytes like : untouched. Rejecting non-token names outright closes the gap.

The check runs everywhere a SQL-supplied header enters, including when a stored table or dictionary is loaded, so one persisted by an older release with such a header name will fail to attach on restart — such a header never worked correctly. Values are unchanged: : stays legal in a value (for example Host: example.com:8080) and a value is rejected only for bare CR/LF.


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

Version info

  • Merged into: 26.10.1.937-master (included in 26.10 and later)

HTTPHeaderFilter compares a header name against each <http_forbid_headers>
entry, but a name like "Cookie:x" is not equal to "Cookie", so it passed
the filter, while a peer still parses a forbidden "Cookie" header from it
because a field name ends at the first ':'. This let a SQL-supplied header
smuggle a forbidden header past the restriction.

Reject a header name that contains ':', CR or LF, checked on the original
bytes so a caller that validates and then sends its own copy cannot emit
them. Whitespace and control characters in a name are still stripped (not
rejected) before the forbidden-header lookup, so attaching a table stored
with such a name keeps working. Values are unchanged (':' stays legal, for
example "Host: example.com:8080"); a value is still rejected for bare
CR/LF. The schema-inference and RestCatalog paths validate and send the
same normalized headers, and schema inference rejects a Range header.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [608a177]

Summary: ✅


AI Review

Summary

This PR hardens HTTPHeaderFilter from name normalization to RFC 9110 token validation and threads the stricter helper through the url family, object-storage headers, HTTP dictionaries, and DataLake auth-header validation. The shared helper itself looks consistent, but DataLakeCatalog still leaves one SQL entrypoint on the old deferred-failure path, so the promised “reject invalid header names supplied to SQL-facing HTTP clients” contract is not yet uniform.

Findings

⚠️ Majors

  • src/Databases/DataLake/DatabaseDataLake.cpp:1585 [dismissed by author -- https://github.com/Reject invalid characters in HTTP header names #118830#discussion_r4082757074] registerDatabaseDataLake still skips auth_header validation for every ATTACH DATABASE, not only for startup metadata replay. A user can therefore submit ATTACH DATABASE ... ENGINE = DataLakeCatalog ... SETTINGS auth_header = 'X A: token', have the DDL succeed, and only hit BAD_ARGUMENTS later on first use when RestCatalog::validateAuthHeaders / UnityV2Catalog::maybeSetAuthHeader finally run under lazy init. That violates the new rejection contract for fresh SQL-supplied input and persists a broken definition that the other tightened HTTP entrypoints now reject up front. Suggested fix: key the startup carve-out on args.is_metadata_replay (and keep RESTORE / explicit user ATTACH in the eager-validation path), then add a regression for explicit ATTACH DATABASE. I still consider this real because DatabaseFactory::Arguments already exposes is_metadata_replay specifically to distinguish replayed metadata from a fresh user ATTACH, so the broad !args.create_query.attach exception is not forced by the engine API.
Tests
  • ⚠️ Add a focused stateless regression that separates startup metadata replay from a fresh user ATTACH DATABASE ... ENGINE = DataLakeCatalog ... SETTINGS auth_header = 'X A: token': replayed metadata can keep the existing lazy-fail startup behavior, but a fresh user ATTACH should either be rejected immediately or the PR description/changelog should explicitly call out that exception.
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  • Either validate auth_header for explicit user ATTACH DATABASE by using the metadata-replay-specific flags already available in DatabaseFactory::Arguments, or narrow the PR description/changelog to state that DataLakeCatalog ATTACH DATABASE remains a deliberate deferred-failure exception.
  • Add the focused regression above once the intended contract is chosen.

LLVM Coverage Report

Measured on commit 608a177.

Metric Baseline Current Δ
Lines 87.90% 87.90% +0.00%
Functions 91.70% 91.80% +0.10%
Branches 79.30% 79.30% +0.00%

Changed lines: Changed C/C++ lines covered: 57/60 (95.00%) · Uncovered code

Full report · Diff report

Comment thread src/Storages/StorageURL.cpp Resolved
@serxa
serxa marked this pull request as ready for review September 8, 2026 17:19
@clickhouse-gh clickhouse-gh Bot added the comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). label Sep 8, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Commit 608a1777c1e913cd9963a5401a5912080ab37715 was not compared: the CI logs cluster did not answer (every POST attempt failed with an exception).

See the job log for details.

Keep this PR to the ':' header-name fix. The Range guard was
inference-correctness, not the security fix, and a behaviour change from
master (which allows a Range header in url() schema inference); it also
covered only the direct StorageURL inference path. Dropped per review;
the normalized-header copy sent during inference is kept.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
serxa added a commit that referenced this pull request Sep 10, 2026
Mirror the drop in the base PR #118830 — keep only the return-normalized
API refactor here, no Range guard. See #118830 for rationale.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Common/HTTPHeaderFilter.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). and removed comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Sep 11, 2026
@serxa

serxa commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

@tavplubix what do you thing about the case where we have wrong header name in a schema that is persistent? If we throw it may lead to crashes that require manual intervention to fix the schema. On the other hand, if we don't throw - we will have an unsecured headers. Maybe we just check it for new queries and read as-is from persisted? But it also sounds a bit fragile to me.

The header filter runs in the StorageURL ctor on every construction,
including ATTACH replay of stored metadata, so a table persisted by an
older release with a now-rejected header name (e.g. a ':') would fail to
attach after upgrade. Gate the validation to freshly supplied definitions
(CREATE / url()) via LoadingStrictnessLevel and skip it when replaying
existing metadata. New input — including the url() table function — is
still rejected; a pre-existing table attaches and sends its stored headers
unchanged.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
serxa added a commit that referenced this pull request Sep 12, 2026
Mirror the base PR #118830: gate the StorageURL header validation to fresh
definitions (CREATE / url()) and skip it on ATTACH replay of existing
metadata, so a table persisted by an older release keeps attaching.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Comment thread src/Common/HTTPHeaderFilter.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). and removed comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). labels Sep 12, 2026
@serxa

serxa commented Sep 12, 2026

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure: https://github.com/ClickHouse/ClickHouse/actions/runs/34691904517/job/103567576644 and provide a fix in a separate PR. If the fix is already in progress, link it here.

Stress test (amd_msan) fails with STID 2508-49e2: Logical error: 'uuid != UUIDHelpers::Nil && getFirstLevelIdx(uuid) < uuid_map.size()' — UUID map consistency check unrelated to this PR's HTTP header name validation changes.

@groeneai

Copy link
Copy Markdown
Collaborator

A fix is already in progress: #111928, open since 2026-07-26.

Your attribution is right, this is not the header name validation. The abort comes from the refreshable materialized view refresh path: RefreshTask::executeRefreshUnlocked -> StorageMaterializedView::prepareRefresh -> InterpreterCreateQuery::createTable -> DatabaseReplicated::tryEnqueueReplicatedDDL -> checkParentTableExists.

#111928 covers the exact frame in that stack. DatabaseReplicatedDDLWorker::checkParentTableExists calls DatabaseCatalog::tryGetByUUID(uuid) with no validation, so a Nil UUID trips the assertion. The PR adds a fail-close Nil guard there, and fixes the source of the Nil: the non-APPEND refreshable MV engine validation is gated on mode <= LoadingStrictnessLevel::CREATE, so a full-definition ATTACH MATERIALIZED VIEW ... REFRESH and a RESTORE remapped into a Memory database both bypass it and leave the view with a Nil StorageID UUID.

I re-checked master today (b8798d61): DatabaseReplicatedWorker.cpp:803 still has the unguarded call, so this recurs on every branch cut from master and merging master does not clear it. CIDB has this assertion on 6 distinct PRs in the last 30 days and 0 rows from master or release branches.

No reviewer has ever been requested on #111928, which is why it has been open for 7 weeks; three earlier carriers of the same assertion got this same link. If you assign a reviewer or review it yourself, the red goes away for all carriers at once.

@tavplubix

tavplubix commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

what do you thing about the case where we have wrong header name in a schema that is persistent? If we throw it may lead to crashes that require manual intervention to fix the schema

See a similar discussion https://github.com/ClickHouse/clickhouse-private/issues/69188#issuecomment-5477882208 https://github.com/ClickHouse/clickhouse-private/issues/69188#issuecomment-5496411954

TL;DR don't listen to the bot, just break it

Per maintainer guidance, don't carve out backward-compat for persisted
headers: a stored header name with ':' / CR / LF never worked correctly
and may indicate a security incident, so reject it everywhere — including
when replaying existing metadata on ATTACH — and make the breakage
visible, rather than reading it back unchecked.

Reverts the fresh-vs-replay gate; the filter again validates
unconditionally in the StorageURL ctor.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... and removed comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Sep 14, 2026
Comment thread src/Databases/DataLake/RestCatalog.cpp Resolved
@serxa

serxa commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

Okay, done

@serxa
serxa requested a review from tavplubix September 14, 2026 20:42
Reject any name byte outside the RFC 7230 token set rather than only ':', whitespace and control characters, so separators such as '/' or '=' no longer pass. Add a regression test.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
The auth_header setting is already validated on every path that sets it (construction and ALTER, via validateAuthHeaders), so re-validating it in getAuthHeaders was unreachable as a distinct check. Replace the ineffective test with one that asserts an invalid auth_header name is rejected when the catalog is built.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Sep 23, 2026
The function validates header names and values and no longer normalizes them, so restore its original name.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…ents

RFC 9110 obsoletes RFC 7230 and carries the token/field-name grammar forward unchanged; reference the current spec.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@clickhouse-gh clickhouse-gh Bot added comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... and removed comp-table-functions Table functions for temporary read/write to external systems (FROM ... tableFunction()). labels Sep 23, 2026
Move the header name/value validation cases into the dedicated filter test (':' , non-tchar separators, empty names rejected; ':' allowed in a value) and drop the duplicates that had accumulated in gtest_gcs_credentials, which reverts to its upstream set.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@serxa

serxa commented Sep 23, 2026 •

Copy link
Copy Markdown
Member Author

I reworked the PR to avoid any normalization, so we are back to where things started before #87172, and weird headers throws an error

The header-name token validation is already covered directly against the
filter in gtest_http_header_filter (WhitespaceOrControlInNameRejected,
NameMustBeToken). The RestCatalog test only re-exercised the pre-existing
validateAuthHeaders wiring, which this change does not modify, while adding a
fragile nine-argument constructor call.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@serxa
serxa requested a review from tavplubix September 23, 2026 15:51
@serxa

serxa commented Sep 24, 2026

Copy link
Copy Markdown
Member Author

@groeneai, investigate the failure on this run and provide a fix in a separate PR. If the fix is already in progress, link it here.

Failing test: test_replicated_database_active_node_taken/test.py::test_active_node_owned_by_another_server
Job: Integration tests (arm_binary, distributed plan, 3/4)

Not related to this PR's HTTP header name validation.

@groeneai

Copy link
Copy Markdown
Collaborator

Confirmed, and not related to your PR: the test is mine. test_active_node_owned_by_another_server came in with #114408, which merged 2026-09-23 00:55Z, and its entire failure history is the 12 hours after that merge (40 failures across 34 distinct PRs plus 5 true-master runs), against zero in the 28 days the test existed before it.

Fix in progress: #121820, test-only, opened 2026-09-23 17:58Z. CREATE DATABASE ... ON CLUSTER had both hosts claim the same replica record concurrently; a host that read the record as absent re-read it inside createReplicaNodesInZooKeeper, found the other host's id and threw REPLICA_ALREADY_EXISTS, which the initiator returned to the client. So the test raised at the CREATE (test.py:40) before reaching the contended active node it is actually about, which is the failure you hit. It now claims the replica one host at a time, node2 carrying node1's database UUID, so the loser is determinate: the old test fails 3 of 20 fresh local runs, the new one passes 50 of 50.

One overlap worth flagging so you are not choosing blindly: #121866 changes the same two files in the same direction, opened about five hours after mine. I have no preference between them; say which one you want kept and I will close #121820 if it is the other.

serxa and others added 2 commits September 28, 2026 12:58
UnityV2Catalog came in from master still calling the old
HTTPHeaderFilter::checkAndNormalizeHeaders name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@serxa
serxa added this pull request to the merge queue Sep 28, 2026
Merged via the queue into master with commit 2bfd008 Sep 28, 2026
150 checks passed
@serxa
serxa deleted the reject-colon-in-http-header-names branch September 28, 2026 18:14
@robot-clickhouse-ci-2 robot-clickhouse-ci-2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 28, 2026
@clickhouse-gh clickhouse-gh Bot added comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... and removed comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... labels Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-networking The connection layer under the protocols, on the server and on the client side: socket read / wri... 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.

4 participants