Skip to content

ModSecurity IIS module add content-length when chunked transfer encoding is enabled #1364

Open
@maverick64

Description

@maverick64

Setup:
Modsecurity + Application Request Routing(ARR) + IIS

ModSecurity is adding content length header even when chunked encoding is enabled. According to RFC (https://www.ietf.org/rfc/rfc2616.txt)
"Messages MUST NOT include both a Content-Length header field and a
non-identity transfer-coding. If the message does include a non-
identity transfer-coding, the Content-Length MUST be ignored."

It is violating the first line of the above and ARR fails it down the pipeline.
The code is in:
iis/mymodule.cpp

apr_status_t WriteBodyCallback(request_rec *r, char *buf, unsigned int length)
{

CHAR szLength[21]; //Max length for a 64 bit int is 20

ZeroMemory(szLength, sizeof(szLength));

HRESULT hr = StringCchPrintfA(
        szLength, 
        sizeof(szLength) / sizeof(CHAR) - 1, "%d", 
        length);

if(FAILED(hr))
{
	// not possible
}

hr = pHttpRequest->SetHeader(
        HttpHeaderContentLength, 
        szLength, 
        (USHORT)strlen(szLength),
        TRUE);

Was this SetHeader Content-lenght intentional?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions