From 65e7edc76ee5f300fa7d846abb932c8927e2296e Mon Sep 17 00:00:00 2001 From: "Alex Z. Yang" Date: Fri, 27 Mar 2020 13:36:22 -0700 Subject: [PATCH] Introducing new return value (-8) in modsecurity_request_body_end when failing to parse JSON bodies; which in turn results in a 400 Bad Request resposne status code in nginx --- apache2/mod_security2.c | 7 +++++++ apache2/msc_reqbody.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apache2/mod_security2.c b/apache2/mod_security2.c index 73662712c2..f96c132145 100755 --- a/apache2/mod_security2.c +++ b/apache2/mod_security2.c @@ -1084,6 +1084,13 @@ static int hook_request_late(request_rec *r) { r->connection->keepalive = AP_CONN_CLOSE; return HTTP_BAD_REQUEST; break; + case -8 : /* JSON body does not parse */ + if (my_error_msg != NULL) { + msr_log(msr, 4, "%s", my_error_msg); + } + r->connection->keepalive = AP_CONN_CLOSE; + return HTTP_BAD_REQUEST; + break; default : /* allow through */ break; diff --git a/apache2/msc_reqbody.c b/apache2/msc_reqbody.c index e84c33a391..4a620ef69a 100644 --- a/apache2/msc_reqbody.c +++ b/apache2/msc_reqbody.c @@ -715,7 +715,7 @@ apr_status_t modsecurity_request_body_end(modsec_rec *msr, char **error_msg) { msr->msc_reqbody_error = 1; msr->msc_reqbody_error_msg = *error_msg; msr_log(msr, 2, "%s", *error_msg); - return -1; + return -8; } #else *error_msg = apr_psprintf(msr->mp, "JSON support was not enabled");