Repository navigation
Reject a bare carriage return in HTTP header names and values - #115510
Conversation
`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]>
|
Workflow [PR], commit [0d546c5] Summary: ✅
AI ReviewSummaryThis PR extends Findings
Final VerdictChanges requested: the local fix is correct for existing LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 18/18 (100.00%) · Uncovered code |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
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 units7 translation units recompiled, 6 s compile time in total, 7 of them have a recent master baseline. |
| /// 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); |
There was a problem hiding this comment.
should we also disallow : and maybe \0?
There was a problem hiding this comment.
\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.
There was a problem hiding this comment.
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.
Backport #115510 to 26.6: Reject a bare carriage return in HTTP header names and values
…HTTP header names and values
Backport #115510 to 26.7: Reject a bare carriage return in HTTP header names and values
Backport #115510 to 26.3: Reject a bare carriage return in HTTP header names and values
…HTTP header names and values
…HTTP header names and values
HTTPHeaderFilter::checkAndNormalizeHeadersrejected an embedded line feed (\n) in HTTP header names and values, but not a bare carriage return (\r). A lone\ralso terminates a header line, so a value such astoken\rX-Injected: evilcould still smuggle a second header into an outgoing request (request/response splitting). This rejects\ralongside\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: theurltable 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):
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 theurltable function and engine, HTTP dictionaries, and data lake catalogs.Version info
26.8.1.1790(included in26.8and later)26.7.7.44,26.6.5.28,26.3.33.23