Skip to content

Commit 2ae357b

Browse files
allanrboFelipe Zimmerle
authored andcommitted
Let body parsers observe SecRequestBodyNoFilesLimit
Previously, modsecurity_request_body_store would keep feeding the body parsers (JSON/XML/Multipart) even after the SecRequestBodyNoFilesLimit limit was met. This change prevents this. Also, modsecurity_request_body_end now returns an error code when the limit is met, so that a message can be logged for this event.
1 parent 89f5427 commit 2ae357b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

apache2/apache2_io.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
335335
apr_brigade_cleanup(bb_in);
336336
} while(!finished_reading);
337337

338-
// TODO: Why ignore the return code here?
339-
modsecurity_request_body_end(msr, error_msg);
338+
apr_status_t rcbe = modsecurity_request_body_end(msr, error_msg);
340339

341340
if (msr->txcfg->debuglog_level >= 4) {
342341
msr_log(msr, 4, "Input filter: Completed receiving request body (length %" APR_SIZE_T_FMT ").",
@@ -345,7 +344,7 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
345344

346345
msr->if_status = IF_STATUS_WANTS_TO_RUN;
347346

348-
return 1;
347+
return rcbe;
349348
}
350349

351350

apache2/msc_reqbody.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,14 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
396396

397397
/* Check that we are not over the request body no files limit. */
398398
if (msr->msc_reqbody_no_files_length >= (unsigned long) msr->txcfg->reqbody_no_files_limit) {
399-
400399
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
401400
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
402401
if (msr->txcfg->debuglog_level >= 1) {
403402
msr_log(msr, 1, "%s", *error_msg);
404403
}
405404

405+
msr->msc_reqbody_error = 1;
406+
406407
if ((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
407408
return -5;
408409
} else if (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL) {
@@ -411,7 +412,6 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
411412
}
412413
}
413414

414-
415415
/* Store data. */
416416
if (msr->msc_reqbody_storage == MSC_REQBODY_MEMORY) {
417417
return modsecurity_request_body_store_memory(msr, data, length, error_msg);
@@ -656,6 +656,19 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) {
656656
/* Note that we've read the body. */
657657
msr->msc_reqbody_read = 1;
658658

659+
660+
/* Check that we are not over the request body no files limit. */
661+
if (msr->msc_reqbody_no_files_length >= (unsigned long)msr->txcfg->reqbody_no_files_limit) {
662+
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
663+
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
664+
if (msr->txcfg->debuglog_level >= 1) {
665+
msr_log(msr, 1, "%s", *error_msg);
666+
}
667+
668+
return -5;
669+
}
670+
671+
659672
/* Finalise body processing. */
660673
if ((msr->msc_reqbody_processor != NULL) && (msr->msc_reqbody_error == 0)) {
661674
char *my_error_msg = NULL;

0 commit comments

Comments
 (0)