Repository navigation
Reject HTTP header values that RFC 2047-decode to CR, LF or NUL - #125497
Conversation
`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]>
|
|
|
Workflow [PR], commit [33711f4] Summary: ✅
AI ReviewSummaryThis PR closes the reported HTTP auth bypass by rejecting request header values that RFC 2047-decode to Final Verdict
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units13 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. |
Backport #125497 to 26.9: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
Backport #125497 to 26.8: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
Backport #125497 to 26.10: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
Backport #125497 to 26.7: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
Backport #125497 to 26.3: Reject HTTP header values that RFC 2047-decode to CR, LF or NUL
…C 2047-decode to CR, LF or NUL
readHeaders(src/Server/HTTP/ReadHeaders.cpp) scans the raw header value for a line break and only afterwards RFC 2047-decodes it withPoco::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_headersof anhttp_authentication_serversentry,HTTPBasicAuthClient::authenticatecopied it verbatim into the request to the authentication server (Poco writes header values as is), before adding its ownAuthorization. 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 duplicateAuthorization(Pythonhttp.server, Node, Flask) answers 200, and ClickHouse authenticates the session asvictim. Reproduced on26.6.1.1193and26.7.5.10.Changes:
readHeadersrejects a value that contains CR, LF or NUL after decoding withMessageException, whichHTTPServerConnectionturns into400 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, includinggetClientHTTPHeaderand multipart part headers inHTMLForm.HTTPBasicAuthClient::authenticatethrowsBAD_ARGUMENTSfor 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_breakchecks 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):
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_headersof an HTTP authentication server could inject extra headers into the request to that server and allow authenticating as another user.Workflow [PR]
Sync PR [sync-upstream/pr/125497]
Version info
26.11.1.595-master(included in26.11and later)26.10.2.90,26.9.26.5,26.8.35.3,26.7.38.14,26.3.61.6