diff --git a/apache2/apache2_io.c b/apache2/apache2_io.c index d3b7eac9..84ba736d 100644 --- a/apache2/apache2_io.c +++ b/apache2/apache2_io.c @@ -84,7 +84,7 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out, return APR_EGENERAL; } - if (chunk && !msr->txcfg->stream_inbody_inspection) { + if (chunk && (!msr->txcfg->stream_inbody_inspection || msr->if_stream_changed == 0)) { /* Copy the data we received in the chunk */ bucket = apr_bucket_heap_create(chunk->data, chunk->length, NULL, f->r->connection->bucket_alloc); @@ -114,6 +114,9 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out, } } else if (msr->stream_input_data != NULL) { + if(msr->if_stream_changed == 1) + msr->if_stream_changed = 0; + bucket = apr_bucket_heap_create(msr->stream_input_data, msr->stream_input_length, NULL, f->r->connection->bucket_alloc); @@ -913,7 +916,10 @@ apr_status_t output_filter(ap_filter_t *f, apr_bucket_brigade *bb_in) { * (full-buffering only). */ if ((msr->of_skipping == 0)&&(!msr->of_partial)) { - inject_content_to_of_brigade(msr,f); + if(msr->of_stream_changed == 1) { + inject_content_to_of_brigade(msr,f); + msr->of_stream_changed = 0; + } prepend_content_to_of_brigade(msr, f); /* Inject content into response (append & buffering). */ diff --git a/apache2/modsecurity.h b/apache2/modsecurity.h index 924dd731..06015487 100644 --- a/apache2/modsecurity.h +++ b/apache2/modsecurity.h @@ -238,6 +238,8 @@ struct modsec_rec { char *stream_input_data; apr_size_t stream_output_length; char *stream_output_data; + unsigned int of_stream_changed; + unsigned int if_stream_changed; apr_array_header_t *error_messages; apr_array_header_t *alerts; diff --git a/apache2/re_operators.c b/apache2/re_operators.c index 36c4ec46..d159e226 100644 --- a/apache2/re_operators.c +++ b/apache2/re_operators.c @@ -442,6 +442,7 @@ static int msre_op_rsub_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, } var->value_len = size; + msr->of_stream_changed = 1; msr->stream_output_data = (char *)stream_output_data; if(msr->stream_output_data != NULL) apr_cpystrn(msr->stream_output_data, data, size); @@ -464,6 +465,7 @@ static int msre_op_rsub_execute(modsec_rec *msr, msre_rule *rule, msre_var *var, msr->stream_input_data = (char *)stream_input_data; if(msr->stream_input_data != NULL) apr_cpystrn(msr->stream_input_data, data, size); + msr->if_stream_changed = 1; } if (! *error_msg) {