Skip to content

Stop buffering when the request is larger than SecRequestBodyLimit in ProcessPartial mode #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions apache2/apache2_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
if (rc == 0) {
modsecurity_request_body_retrieve_end(msr);

bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc);
if (bucket == NULL) return APR_EGENERAL;
APR_BRIGADE_INSERT_TAIL(bb_out, bucket);
if (msr->if_seen_eos) {
bucket = apr_bucket_eos_create(f->r->connection->bucket_alloc);
if (bucket == NULL) return APR_EGENERAL;
APR_BRIGADE_INSERT_TAIL(bb_out, bucket);

if (msr->txcfg->debuglog_level >= 4) {
msr_log(msr, 4, "Input filter: Sent EOS.");
if (msr->txcfg->debuglog_level >= 4) {
msr_log(msr, 4, "Input filter: Sent EOS.");
}
}

/* We're done */
Expand All @@ -164,7 +166,7 @@ apr_status_t input_filter(ap_filter_t *f, apr_bucket_brigade *bb_out,
*/
apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
request_rec *r = msr->r;
unsigned int seen_eos;
unsigned int finished_reading;
apr_bucket_brigade *bb_in;
apr_bucket *bucket;

Expand Down Expand Up @@ -193,7 +195,8 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
return -1;
}

seen_eos = 0;
finished_reading = 0;
msr->if_seen_eos = 0;
bb_in = apr_brigade_create(msr->mp, r->connection->bucket_alloc);
if (bb_in == NULL) return -1;
do {
Expand Down Expand Up @@ -283,6 +286,11 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {

if (buflen != 0) {
int rcbs = modsecurity_request_body_store(msr, buf, buflen, error_msg);

if (msr->reqbody_length > (apr_size_t)msr->txcfg->reqbody_limit && msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL) {
finished_reading = 1;
}

if (rcbs < 0) {
if (rcbs == -5) {
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
Expand All @@ -309,12 +317,13 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
}

if (APR_BUCKET_IS_EOS(bucket)) {
seen_eos = 1;
finished_reading = 1;
msr->if_seen_eos = 1;
}
}

apr_brigade_cleanup(bb_in);
} while(!seen_eos);
} while(!finished_reading);

// TODO: Why ignore the return code here?
modsecurity_request_body_end(msr, error_msg);
Expand Down
1 change: 1 addition & 0 deletions apache2/modsecurity.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ struct modsec_rec {
unsigned int phase_request_body_complete;

apr_bucket_brigade *if_brigade;
unsigned int if_seen_eos;
unsigned int if_status;
unsigned int if_started_forwarding;

Expand Down