Skip to content

Reject a bare carriage return in HTTP header names and values - #115510

Merged
serxa merged 1 commit into
masterfrom
reject-bare-cr-in-http-headers
Aug 20, 2026
Merged

serxa merged 1 commit into
masterfrom
reject-bare-cr-in-http-headers

Conversation

@serxa

@serxa serxa commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

HTTPHeaderFilter::checkAndNormalizeHeaders rejected an embedded line feed (\n) in HTTP header names and values, but not a bare carriage return (\r). A lone \r also terminates a header line, so a value such as token\rX-Injected: evil could still smuggle a second header into an outgoing request (request/response splitting). This rejects \r alongside \n, for both header names and values, in the shared filter.

This covers the callers that route header names/values through HTTPHeaderFilter — the SQL-facing paths where headers are supplied per query: the url table function and engine, HTTP dictionaries, S3/Web configuration, and the DataLake/REST catalogs. Outbound HTTP clients that build headers without this filter (for example the AI providers and the BigQuery client, whose header values come from named collections, OAuth tokens, or DDL configuration) are not affected by this change; enforcing the same invariant at the shared HTTP send path for those clients is left to a separate follow-up.

Deferred from #110313 to keep that pull request focused on refactoring.

Related: #110313

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 a bare carriage return (\r), in addition to a line feed (\n), in HTTP header names and values that pass through the HTTP header filter. This closes an HTTP header injection (request/response splitting) gap for features that pass user-provided headers, such as the url table function and engine, HTTP dictionaries, and data lake catalogs.

Version info

  • Merged into: 26.8.1.1790 (included in 26.8 and later)
  • Backported to: 26.7.7.44, 26.6.5.28, 26.3.33.23

`HTTPHeaderFilter::checkAndNormalizeHeaders` rejected an embedded `\n` but not a
bare `\r`. A lone CR also terminates a header line, so a value such as
"token\rX-Injected: evil" could still smuggle a second header (request/response
splitting). Reject `\r` alongside `\n` for both header names and values, closing
the gap for every caller of the shared filter.

Deferred from #110313 to keep that
pull request focused on refactoring.

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

clickhouse-gh Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [0d546c5]

Summary: ✅


AI Review

Summary

This PR extends HTTPHeaderFilter::checkAndNormalizeHeaders to reject a bare carriage return in header names and values, and the added unit test covers the shared filter itself well. That fixes the url / dictionary / data-lake / S3-Web callers that already go through HTTPHeaderFilter, but the same outbound-header invariant is still missing in sibling HTTP clients that synthesize headers directly from user-configured strings, so the broader request-splitting bug class is not fully closed yet.

Findings

⚠️ Majors

  • [src/Common/HTTPHeaderFilter.cpp:26] The new security invariant only applies to HTTPHeaderFilter callers. src/Storages/BigQuery/BigQueryClient.cpp:217-220 still sends Authorization and X-Goog-User-Project directly from configuration, and the AI providers still send Authorization / x-api-key directly from api_key in src/Functions/AI/OpenAIProvider.cpp:65, src/Functions/AI/OpenAIProvider.cpp:150, and src/Functions/AI/AnthropicProvider.cpp:84. Those paths still feed raw values to request.set(...), so a bare \r can still split the outgoing request there. Suggested fix: move the CR/LF rejection into a shared helper used by every outbound-header construction site, or at least apply the same validation in these sibling clients before claiming the bug class is fixed.
Final Verdict

Changes requested: the local fix is correct for existing HTTPHeaderFilter callers, but the broader outbound-header contract remains un-enforced in sibling clients that synthesize headers directly.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.90% 86.90% +0.00%
Functions 91.90% 91.90% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 19, 2026
Comment thread src/Common/HTTPHeaderFilter.cpp Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 0d546c580 with master 27f733d4f (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 703.88 MiB 700.84 MiB -3.04 MiB (-0.43%)

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.

Compile time of recompiled translation units

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

Job report

@serxa
serxa marked this pull request as ready for review August 20, 2026 11:33
/// carrying one could smuggle a second header into the request (request/response splitting).
if (entry.name.contains('\n') || entry.value.contains('\n')
|| entry.name.contains('\r') || entry.value.contains('\r'))
throw Exception(ErrorCodes::BAD_ARGUMENTS, "HTTP header \"{}\" has invalid character", entry.name);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also disallow : and maybe \0?

@serxa serxa Aug 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\r/\n are the request-splitting, : is safe (e.g. host:port), it's malformed in name but doesn't split the line. A \0 in a name is already stripped by the existing control-char normalization; in a value, it truncates rather than splits.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three of the four claims hold. The : one doesn't, and it's the load-bearing one — I have a working repro against a real server.

: in a name is not safe

The comment's test — "does it split the line?" — is the right test for request splitting and the wrong test for this filter. http_forbid_headers exists to guarantee "a SQL user cannot cause header X to be sent." : breaks that guarantee without splitting anything, because the
peer's field-name/field-value boundary is the first colon, and the filter compares the whole string.

Server running with <http_forbid_headers>

Cookie</http_forbid_headers>:

CASE A — headers('Cookie' = 'session=abc')
Code: 36. HTTP header "Cookie" is forbidden in configuration file ✅ blocked

CASE B — headers('Cookie:j="x' = 'y";session=abc')
filter: not blocked
wire: Cookie:j="x: y";session=abc\r\n

Feeding those exact bytes to a real HTTP parser:

peer Cookie header = 'j="x: y";session=abc'
peer parsed cookies = {'j': 'x: y', 'session': 'abc'}

session=abc arrives intact. The mandatory ": " that Poco inserts (base/poco/Net/src/MessageHeader.cpp:64) is swallowed inside a quoted throwaway cookie, so there's no contamination of the real payload. No control characters, no lenient parser required — Python's http.server +
SimpleCookie are strict, and it still works.

Two honest caveats on scope: this only matters where http_forbid_headers is actually configured, and my first-attempt payloads (Cookie:session=abc;junk) did get mangled by the trailing ": " — the quote-swallow trick was needed to make it clean. The same shape works on
X-Forwarded-For without any trick, since 1.2.3.4,: 9.9.9.9 splits on , into a clean leftmost 1.2.3.4.

Where the comment is right: : in a value is completely normal (Host: example.com:8080) and must stay allowed. The fix is : in names only — which is exactly what the RFC 9110 token rule gives you, since : isn't a tchar.

The other three claims are correct

  • \r/\n are the request-splitting characters — yes.
  • \0 in a name is already stripped by the existing normalization — correct as stated about the function. I over-weighted this in my first message. The only residual gap is a caller bug, not a charset one: src/Storages/StorageURL.cpp:1093 validates a copy and then passes the
    original headers to URLReadBufferIterator at :1105, so on that one path the raw NUL reaches the wire. Exploiting it further needs a C-string-based peer, which most modern servers aren't. Low severity; worth closing when the copy goes away, not worth arguing over.
  • \0 in a value truncates rather than splits — correct, and it buys an attacker nothing, since they already control the value and truncation only makes the peer see less. Agreed it's not a vector.

So: the comment's conclusion "only \r/\n matter" is right about splitting and wrong about this filter. If you're revising it, the substantive change is dropping ": is safe" and separating names from values — the host:port example is about values and doesn't defend : in names.

Test artifacts are under tmp/ (hdrcap.py, parse.py, srv/) if you want to re-run any of it; the test server is stopped.

@tavplubix tavplubix self-assigned this Aug 20, 2026
@serxa
serxa enabled auto-merge August 20, 2026 18:06
@serxa
serxa added this pull request to the merge queue Aug 20, 2026
Merged via the queue into master with commit ea3d0db Aug 20, 2026
180 checks passed
@serxa
serxa deleted the reject-bare-cr-in-http-headers branch August 20, 2026 19:39
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label Aug 20, 2026
@antonio2368 antonio2368 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Sep 2, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Sep 2, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Sep 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 2, 2026
Backport #115510 to 26.6: Reject a bare carriage return in HTTP header names and values
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 4, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 7, 2026
Backport #115510 to 26.7: Reject a bare carriage return in HTTP header names and values
antonio2368 added a commit that referenced this pull request Sep 9, 2026
Backport #115510 to 26.3: Reject a bare carriage return in HTTP header names and values
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

7 participants