IIS: Content-Length header corrupted/truncated for large responses (wrong printf format + off-by-one buffer size)
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 84/100
Research direction
Start in iis/mymodule.cpp at the three affected StringCchPrintfA call sites around lines 642, 1140, and 1228, and review the Windows API's destination-size and format-string requirements. Build the IIS module and exercise response paths with large lengths; done means all three Content-Length values are correctly represented without truncation.
Written by the indexing model from the issue text.
Description
Summary
In iis/mymodule.cpp, StringCchPrintfA is used to build the Content-Length header value, but it has two defects that corrupt the header for large responses:
- Wrong format specifier for 64-bit value. At the response path,
ulTotalLengthis aULONGLONG, but it is printed with"%d"(which expects a 32-bitint).printfonly reads the low 32 bits, so the resultingContent-Lengthis wrong whenever the response body exceeds ~2 GiB. The other two call sites format anunsigned intlengthwith"%d"as well (should be%u). - Off-by-one destination size.
StringCchPrintfA'scchDestargument is passed assizeof(szLength)/sizeof(CHAR) - 1(= 20). Since this argument must include the null terminator, the buffer can only hold 19 digits. A 64-bit value can be 20 decimal digits (e.g.18446744073709551615), so it is silently truncated / the call fails.
Impact
When ModSecurity for IIS must synthesize the Content-Length header (the only-response, non-chunked case), a wrong value causes clients to hang or error because the body length does not match the advertised header.
Affected locations (v2/master)
iis/mymodule.cpp:642—ulTotalLength(ULONGLONG) ->"%llu"iis/mymodule.cpp:1140—length(unsigned int) ->"%u"iis/mymodule.cpp:1228—length(unsigned int) ->"%u"
All three should also pass the full buffer size sizeof(szLength)/sizeof(CHAR) (21) instead of ... - 1.
Suggested fix
CHAR szLength[21]; // Max length for a 64-bit int is 20 digits + null
ZeroMemory(szLength, sizeof(szLength));
HRESULT hr = StringCchPrintfA(
szLength,
sizeof(szLength) / sizeof(CHAR), // includes null terminator
"%llu", // ULONGLONG
ulTotalLength);
- Dominant language
- C++
- Stars
- 9.8k
- Forks
- 1.8k
- Avg merge
- 2h 46m
- Merged PRs (30d)
- 1
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from owasp-modsecurity/ModSecurity
-
2.x Platform - IIS
Difficulty 1/5 Under an hour Newbie friendliness 90/100
owasp-modsecurity/ModSecurity#3623 · 1 comment ·
-
2.x Platform - IIS
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
owasp-modsecurity/ModSecurity#3621 · 1 comment ·
-
2.x Platform - IIS
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
owasp-modsecurity/ModSecurity#3612 · 1 comment ·
-
3.x
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
owasp-modsecurity/ModSecurity#3580 · 1 comment ·
-
2.x Platform - IIS
Difficulty 2/5 1-3 hours Newbie friendliness 25/100
owasp-modsecurity/ModSecurity#3630 ·
All issues in owasp-modsecurity/ModSecurity
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·