Skip to content

Reject HTTP header values that RFC 2047-decode to CR, LF or NUL - #125497

Merged
alexey-milovidov merged 2 commits into
masterfrom
cursor/http-header-rfc2047-crlf-2579
Oct 22, 2026
Merged

alexey-milovidov merged 2 commits into
masterfrom
cursor/http-header-rfc2047-crlf-2579

Conversation

@yakov-olkhovskiy

@yakov-olkhovskiy yakov-olkhovskiy commented Oct 12, 2026 •

Copy link
Copy Markdown
Member

readHeaders (src/Server/HTTP/ReadHeaders.cpp) scans the raw header value for a line break and only afterwards RFC 2047-decodes it with Poco::Net::MessageHeader::decodeWord, storing the result without re-checking it. Both the Q encoding (=0D=0A) and the B encoding (base64) can therefore produce a stored value containing a real CRLF or NUL.

When such a header is listed in forward_headers of an http_authentication_servers entry, HTTPBasicAuthClient::authenticate copied it verbatim into the request to the authentication server (Poco writes header values as is), before adding its own Authorization. An attacker holding any credential the backend accepts could send -u victim:wrong -H 'Custom-Header: =?UTF-8?Q?x=0D=0AAuthorization:_Basic_<attacker creds>?='; a backend honouring the first duplicate Authorization (Python http.server, Node, Flask) answers 200, and ClickHouse authenticates the session as victim. Reproduced on 26.6.1.1193 and 26.7.5.10.

Changes:

  • readHeaders rejects a value that contains CR, LF or NUL after decoding with MessageException, which HTTPServerConnection turns into 400 Bad Request (RFC 9110, section 5.5 permits rejecting such messages). This fixes the issue at the source for all consumers of the parsed headers, including getClientHTTPHeader and multipart part headers in HTMLForm.
  • Defence in depth: HTTPBasicAuthClient::authenticate throws BAD_ARGUMENTS for a forwarded value containing CR, LF or NUL instead of writing it into the outgoing request, so authentication fails closed.

The new stateless test 05339_http_header_rfc2047_line_break checks Q-encoded CRLF and LF, B-encoded CRLF, an encoded NUL and an encoded word in the middle of a value, and that regular encoded words (café) are still decoded.

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Reject HTTP requests with a header value that contains CR, LF or NUL after RFC 2047 decoding. Previously such a header listed in forward_headers of an HTTP authentication server could inject extra headers into the request to that server and allow authenticating as another user.

Open in Web Open in Cursor 

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

Version info

  • Merged into: 26.11.1.595-master (included in 26.11 and later)
  • Backported to: 26.10.2.90, 26.9.26.5, 26.8.35.3, 26.7.38.14, 26.3.61.6

cursoragent and others added 2 commits October 12, 2026 20:25
`readHeaders` scanned the raw header value for a line break and only then
RFC 2047-decoded it with `Poco::Net::MessageHeader::decodeWord`, so an
encoded word such as `=?UTF-8?Q?x=0D=0AAuthorization:_...?=` produced a
stored value with a real CRLF. When such a header is listed in
`forward_headers` of an HTTP authentication server, it split the outgoing
request and injected an `Authorization` header placed before ours, which
allowed authenticating as another user.

Validate the decoded value and reject the request with 400 Bad Request
(RFC 9110, section 5.5).

Co-authored-by: yakov <[email protected]>
`HTTPBasicAuthClient::authenticate` copied forwarded header values into the
outgoing request verbatim. Reject values containing CR, LF or NUL, so a value
from any producer cannot inject headers into the request to the
authentication server.

Co-authored-by: yakov <[email protected]>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@clickhouse-gh

clickhouse-gh Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [33711f4]

Summary: ✅


AI Review

Summary

This PR closes the reported HTTP auth bypass by rejecting request header values that RFC 2047-decode to CR, LF, or NUL before they enter ClientInfo, and by re-validating forwarded headers before HTTPBasicAuthClient copies them into the auth-server request. I did not find an unresolved contract violation in the touched paths: the parser-level fix blocks the exploit at ingress, the defence-in-depth check fails closed if a bad value still reaches the forwarding path, and the added stateless regression covers the ingress rejection plus the non-malicious decoding behavior that must keep working.

Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Oct 12, 2026
@yakov-olkhovskiy
yakov-olkhovskiy marked this pull request as ready for review October 12, 2026 20:27
@clickhouse-gh clickhouse-gh Bot added the comp-protocols Server wire protocols + request/response handling (native TCP, HTTP, MySQL/PostgreSQL wire protoc... label Oct 12, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 33711f47a with master 6149a2354 (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

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.

Compile time of recompiled translation units

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

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

Job report

@alexey-milovidov alexey-milovidov self-assigned this Oct 22, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Oct 22, 2026
Merged via the queue into master with commit 889a695 Oct 22, 2026
177 checks passed
@alexey-milovidov
alexey-milovidov deleted the cursor/http-header-rfc2047-crlf-2579 branch October 22, 2026 23:22
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 22, 2026
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Oct 22, 2026
@robot-clickhouse robot-clickhouse added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 22, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #125497 to 26.9: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #125497 to 26.8: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #125497 to 26.10: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
clickhouse-gh Bot added a commit that referenced this pull request Oct 23, 2026
Backport #125497 to 26.7: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
alexey-milovidov added a commit that referenced this pull request Oct 23, 2026
Backport #125497 to 26.3: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
leshikus pushed a commit that referenced this pull request Nov 13, 2026
VighneshPath pushed a commit to VighneshPath/ClickHouse that referenced this pull request Nov 23, 2026
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-critical-bugfix 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.

6 participants