@@ -362,6 +362,18 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
362362 /* Increase per-request data length counter. */
363363 msr -> msc_reqbody_no_files_length += length ;
364364
365+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
366+ if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
367+ && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
368+ {
369+ length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
370+ if (msr -> txcfg -> debuglog_level >= 9 ) {
371+ msr_log (msr , 9 , "XML: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
372+ msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
373+ }
374+ modsecurity_request_body_enable_partial_processing (msr );
375+ }
376+
365377 /* Process data as XML. */
366378 if (xml_process_chunk (msr , data , length , & my_error_msg ) < 0 ) {
367379 * error_msg = apr_psprintf (msr -> mp , "XML parsing error: %s" , my_error_msg );
@@ -374,6 +386,18 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
374386 /* Increase per-request data length counter. */
375387 msr -> msc_reqbody_no_files_length += length ;
376388
389+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
390+ if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
391+ && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
392+ {
393+ length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
394+ if (msr -> txcfg -> debuglog_level >= 9 ) {
395+ msr_log (msr , 9 , "JSON: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
396+ msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
397+ }
398+ modsecurity_request_body_enable_partial_processing (msr );
399+ }
400+
377401 /* Process data as JSON. */
378402#ifdef WITH_YAJL
379403 if (json_process_chunk (msr , data , length , & my_error_msg ) < 0 ) {
@@ -393,6 +417,18 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
393417 /* Increase per-request data length counter. */
394418 msr -> msc_reqbody_no_files_length += length ;
395419
420+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
421+ if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
422+ && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
423+ {
424+ length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
425+ if (msr -> txcfg -> debuglog_level >= 9 ) {
426+ msr_log (msr , 9 , "URLENCODED: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
427+ msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
428+ }
429+ modsecurity_request_body_enable_partial_processing (msr );
430+ }
431+
396432 /* Do nothing else, URLENCODED processor does not support streaming. */
397433 }
398434 else {
@@ -403,6 +439,18 @@ apr_status_t modsecurity_request_body_store(modsec_rec *msr,
403439 } else if (msr -> txcfg -> reqbody_buffering != REQUEST_BODY_FORCEBUF_OFF ) {
404440 /* Increase per-request data length counter if forcing buffering. */
405441 msr -> msc_reqbody_no_files_length += length ;
442+
443+ /* Enable partial processing if no_files_len exceeds limit and action is ProcessPartial */
444+ if ( (msr -> msc_reqbody_no_files_length > (unsigned long )msr -> txcfg -> reqbody_no_files_limit )
445+ && (msr -> txcfg -> if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL ))
446+ {
447+ length -= msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit ;
448+ if (msr -> txcfg -> debuglog_level >= 9 ) {
449+ msr_log (msr , 9 , "forceBuf: length shortened by %" APR_SIZE_T_FMT " bytes because of no_files_len limit." ,
450+ msr -> msc_reqbody_no_files_length - (unsigned long )msr -> txcfg -> reqbody_no_files_limit );
451+ }
452+ modsecurity_request_body_enable_partial_processing (msr );
453+ }
406454 }
407455
408456 /* Check that we are not over the request body no files limit. */
0 commit comments