Skip to content

Commit c712a16

Browse files
Felipe Zimmerledaniilyar
Felipe Zimmerle
authored andcommitted
nginx: copies the req body chain to be processed instead of move
Add a check for the definition MOVE_REQUEST_CHAIN_TO_MODSEC, whenever it is set the chain will be moved into the brigade. If it was not set the chain will be only copied. Moving was causing segfaults on the following regression tests: owasp-modsecurity#15 - SecRequestBodyInMemoryLimit owasp-modsecurity#16 - SecRequestBodyInMemoryLimit (greater) owasp-modsecurity#19 - SecRequestBodyLimitAction ProcessPartial (multipart/greater - chunked) (from: regression/config/10-request-directives.t)
1 parent 49cf8b8 commit c712a16

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

nginx/modsecurity/ngx_http_modsecurity.c

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
/* Those are defined twice, lets keep it defined just once by `undef`
2222
* the first one.
2323
*/
24-
*/
2524
#undef CR
2625
#undef LF
2726
#undef CRLF
@@ -566,7 +565,6 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
566565
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
567566
"ModSec: loading request body.");
568567

569-
570568
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
571569
"ModSec: loading request body.");
572570

@@ -600,6 +598,10 @@ ngx_http_modsecurity_load_request_body(ngx_http_request_t *r)
600598
}
601599
#endif
602600

601+
return NGX_ERROR;
602+
}
603+
#endif
604+
603605
return NGX_OK;
604606
}
605607
static ngx_inline ngx_int_t
@@ -610,6 +612,7 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
610612
apr_off_t content_length;
611613
ngx_buf_t *buf;
612614
#endif
615+
613616
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity);
614617

615618
#ifdef MOVE_REQUEST_CHAIN_TO_MODSEC
@@ -652,10 +655,15 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
652655

653656
}
654657

655-
656658
r->headers_in.content_length_n = content_length;
657659

658-
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "ModSec: Content length: %O, Content length n: %O", content_length, r->headers_in.content_length_n);
660+
ngx_log_debug(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
661+
"ModSec: Content length: %O, Content length n: %O", content_length,
662+
r->headers_in.content_length_n);
663+
#else
664+
apr_brigade_cleanup(ctx->brigade);
665+
#endif
666+
659667
return NGX_OK;
660668
}
661669

@@ -1238,10 +1246,18 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12381246

12391247
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
12401248
"ModSec: request is ready to be processed.");
1241-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1242-
"ModSec: chuncked? %d", r->chunked);
1243-
ngx_http_modsecurity_process_request(r);
1249+
rc = ngx_http_modsecurity_process_request(r);
12441250
ctx->request_processed = 1;
1251+
1252+
if (rc == NGX_ERROR || rc >= NGX_HTTP_SPECIAL_RESPONSE) {
1253+
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1254+
"ModSec: returning a special response after process " \
1255+
"a request: %d", rc);
1256+
1257+
return rc;
1258+
}
1259+
1260+
12451261
}
12461262

12471263
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,

0 commit comments

Comments
 (0)