Repository navigation
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
631e49b to
18c40c7
Compare
|
fzipi
left a comment
There was a problem hiding this comment.
Thanks @A13501350! I traced this through modsecProcessRequest → WriteBodyCallback. This is the request side: we buffer the body, re-insert the de-chunked bytes with InsertEntityBody and set our own Content-Length. If Transfer-Encoding: chunked is left on the request, anything downstream that honors TE over CL (RFC 9112 §6.3), such as an ARR backend, would parse a body that differs from what ModSecurity inspected. So removing TE, rather than rejecting the request, is the right call: the chunked upload itself was legitimate, and only our rewrite made the headers inconsistent.
- (blocking) The exact
stricmp(..., "chunked")match misseschunked, chunked,gzip, chunked, trailing whitespace and so on. If HTTP.SYS passes any of these through to the module, those requests would still end up with both headers. Since we set an authoritativeContent-Lengthright after, anyTransfer-Encodingis stale at that point, so I'd just drop it unconditionally:pHttpRequest->DeleteHeader(HttpHeaderTransferEncoding);. If you prefer to keep a check, please at least use a case-insensitive substring match, like the engine does inmodsecurity.c(m_strcasestr(te, "chunked")). - (non-blocking) Small wording tweak for the comment: something like "we re-insert the de-chunked body with an explicit Content-Length, so Transfer-Encoding no longer applies".
- (non-blocking) Once #3613's ARR/albedo harness is in, a chunked POST that checks the forwarded headers would be a nice regression test for this.
18c40c7 to
69dfb2e
Compare
|
The previous fix used stricmp() to match "chunked" exactly, which misses Transfer-Encoding values like "chunked, chunked", "gzip, chunked", or anything with extra whitespace. Since ModSecurity always forwards the body with an explicit Content-Length immediately after this point, any Transfer-Encoding header copied from the original request is stale and must be removed regardless of its value. Delete unconditionally.
69dfb2e to
ef1168b
Compare
|
A13501350
left a comment
There was a problem hiding this comment.
@fzipi Updated in 69dfb2e1 to drop Transfer-Encoding unconditionally via pHttpRequest->DeleteHeader(HttpHeaderTransferEncoding) and revised the inline comment.
Verified a chunked POST through IIS + ARR + albedo on a test branch: the forwarded request no longer triggers ARR's CL+TE 502 and is inspected in phase 2. The permanent FTW regression test will follow once #3613's iis/tests harness lands.



Summary
In
iis/mymodule.cpp,WriteBodyCallbackcopies the inbound request headers verbatim (includingTransfer-Encoding) and then setsContent-Lengthon the request. The result can be a request that carries bothTransfer-Encoding: chunkedandContent-Length, which is malformed and is rejected by some backends / causes ambiguous framing.Change
Right before setting
Content-Length, deleteTransfer-Encodingunconditionally viapHttpRequest->DeleteHeader(HttpHeaderTransferEncoding). Since the de-chunked body is re-inserted with an authoritativeContent-Length, any priorTransfer-Encodingis stale regardless of value, and only one framing header remains on the forwarded request.Provenance
Adapted from
microsoft/ModSecuritybranchwaf_iis. Verified still missing on currentv2/mastertip (0875b19, v2.9.14).