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
|
A13501350
force-pushed
the
fix/issue-3397-reqbody-fd
branch
from
December 2, 2026 15:27
4d914d0 to
85f2e2b
Compare
A13501350
force-pushed
the
fix/issue-3397-reqbody-fd
branch
from
December 2, 2026 15:30
85f2e2b to
b13765c
Compare
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Fixes #3397 (re-verified on current
v2/master, where #3624 did not address this crash because #3624 was in response-sideReadFileChunk(), whereas #3397 occurs during request body ingestion).Root Cause
On Windows (observed on Windows Server 2025 / IIS 10.0), when a request body exceeds
SecRequestBodyInMemoryLimit(131072bytes out of the box) and temporary file creation fails (for example,SecTmpDir c:\inetpub\temp\is not writable by the IIS AppPool identity, the directory does not exist, orSecTmpDir noneis configured):modsecurity_request_body_store_memory()switchedmsr->msc_reqbody_storagetoMSC_REQBODY_DISKbeforemodsecurity_request_body_start_init()succeeded, leavingmsr->msc_reqbody_fd = -1(andmsr->msc_reqbody_filenamepopulated even though no file was created).read_request_body()(apache2/apache2_io.c), internal storage errors (rcbs < 0withrcbs != -5) were only aborted whenis_enabled == MODSEC_ENABLED && if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT. Under out-of-the-boxSecRuleEngine DetectionOnly(orProcessPartial), the loop swallowed-1and continued reading subsequent chunks.modsecurity_request_body_store_disk()called CRTwrite(-1, data, length). Unlike POSIX (which returnsEBADF), Windows UCRT invokes the invalid-parameter handler (ucrtbase!invoke_watson/FAST_FAIL_INVALID_ARG, exception0xc0000409inucrtbase.dll), crashingw3wp.exe.Reproduced WER / debugger stack trace on v2/master prior to this fix
1000:w3wp.exe(10.0.26100.1882), faulting moduleucrtbase.dll(10.0.26100.33648), exception0xc0000409, offset0x000000000001cba8.cdb.exe.ecxr; k(Subcode: 0x5 FAST_FAIL_INVALID_ARG):Changes
apache2/msc_reqbody.c:msr->txcfg->tmp_dir == NULLinmodsecurity_request_body_start_init(), setmsr->msc_reqbody_fd = -1, and only assignmsr->msc_reqbody_filenameoncemsc_mkstemp()succeeds (avoiding spurious"Failed to delete temporary file"errors inmodsecurity_request_body_clear()).msr->msc_reqbody_storage = MSC_REQBODY_MEMORYifmodsecurity_request_body_start_init()fails during spill-to-disk inmodsecurity_request_body_store_memory().msr->msc_reqbody_fd < 0inmodsecurity_request_body_store_disk()andmodsecurity_request_body_retrieve(), andmsr->msc_reqbody_filename == NULLinmodsecurity_request_body_retrieve_start().apache2/apache2_io.c:read_request_body(), returnHTTP_INTERNAL_SERVER_ERRORfor non-limit (rcbs != -5)modsecurity_request_body_store()failures regardless ofSecRuleEngine DetectionOnlyorSecRequestBodyLimitAction ProcessPartial(consistent withmodsecurity_request_body_start(),modsecurity_request_body_to_stream(), andmodsecurity_request_body_end()).apache2/msc_multipart.c:msr->txcfg->tmp_dir == NULLand only assignmsr->mpd->mpp->tmp_file_nameaftermsc_mkstemp_ex()succeeds.msr->mpd->mpp->tmp_file_fd != 0to> 0inmultipart_process_boundary()soclose(-1)cannot be called on UCRT.Note for Windows / IIS deployments
Out of the box on Windows Server,
C:\inetpub\temp\is not writable byIIS_IUSRS/ AppPool identities, so uploads exceedingSecRequestBodyInMemoryLimit(131072) requireSecTmpDirto point to a directory writable by the AppPool identity. With this fix, ifSecTmpDiris missing or not writable, ModSecurity cleanly logs the temporary file creation error and returns HTTP 500 instead of crashingw3wp.exe.Verification
Tested on GitHub Actions (
windows-latest/ Windows Server 2025,RelWithDebInfo):go-ftwCRS regression suite passed (exit code 0).DetectionOnlyandOn,RejectandProcessPartial, defaultc:\inetpub\temp\, writableSecTmpDir, missingSecTmpDir, andSecTmpDir none): zerow3wp.execrashes, zero WER dumps, and zero Event ID 1000 entries (actions/runs/46908964436).