Skip to content

Commit b3ba9c4

Browse files
author
Felipe Zimmerle
committed
nginx: better dealing with chunked request body
1 parent e60154d commit b3ba9c4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

nginx/modsecurity/ngx_http_modsecurity.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,23 @@ ngx_http_modsecurity_save_request_body(ngx_http_request_t *r)
639639
apr_brigade_cleanup(ctx->brigade);
640640
#endif
641641

642+
if (r->headers_in.content_length) {
643+
ngx_str_t *str = NULL;
644+
645+
str = &r->headers_in.content_length->value;
646+
str->data = ngx_palloc(r->pool, NGX_OFF_T_LEN);
647+
if (str->data == NULL) {
648+
ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
649+
return NGX_OK;
650+
}
651+
str->len = ngx_snprintf(str->data, NGX_OFF_T_LEN, "%O", content_length) - str->data;
652+
653+
}
654+
655+
642656
r->headers_in.content_length_n = content_length;
643657

644-
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);
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);
645659
return NGX_OK;
646660
}
647661

@@ -1221,8 +1235,11 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r) {
12211235
}
12221236

12231237
if (ctx->waiting_more_body == 0 && ctx->request_processed == 0) {
1238+
12241239
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
12251240
"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);
12261243
ngx_http_modsecurity_process_request(r);
12271244
ctx->request_processed = 1;
12281245
}

0 commit comments

Comments
 (0)