mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 13:56:01 +03:00
Improvements in detection only
This commit is contained in:
parent
13980bd044
commit
b8828ad3f1
@ -1750,12 +1750,7 @@ static const char *cmd_resquest_body_limit_action(cmd_parms *cmd, void *_dcfg,
|
||||
directory_config *dcfg = (directory_config *)_dcfg;
|
||||
if (dcfg == NULL) return NULL;
|
||||
|
||||
if (dcfg->is_enabled == MODSEC_DETECTION_ONLY) {
|
||||
dcfg->if_limit_action = REQUEST_BODY_LIMIT_ACTION_PARTIAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (strcasecmp(p1, "ProcessPartial") == 0) dcfg->if_limit_action = RESPONSE_BODY_LIMIT_ACTION_PARTIAL;
|
||||
if (strcasecmp(p1, "ProcessPartial") == 0) dcfg->if_limit_action = REQUEST_BODY_LIMIT_ACTION_PARTIAL;
|
||||
else
|
||||
if (strcasecmp(p1, "Reject") == 0) dcfg->if_limit_action = REQUEST_BODY_LIMIT_ACTION_REJECT;
|
||||
else
|
||||
|
@ -236,27 +236,57 @@ apr_status_t read_request_body(modsec_rec *msr, char **error_msg) {
|
||||
|
||||
/* Check request body limit (should only trigger on chunked requests). */
|
||||
if (msr->reqbody_length + buflen > (apr_size_t)msr->txcfg->reqbody_limit) {
|
||||
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_limit);
|
||||
if(msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)
|
||||
return -5;
|
||||
} else if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)) {
|
||||
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_limit);
|
||||
|
||||
seen_eos = 1;
|
||||
|
||||
buflen = (msr->txcfg->reqbody_limit - msr->reqbody_length);
|
||||
|
||||
} else if ((msr->txcfg->is_enabled == MODSEC_DETECTION_ONLY) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)){
|
||||
|
||||
seen_eos = 1;
|
||||
buflen = (msr->txcfg->reqbody_limit - msr->reqbody_length);
|
||||
|
||||
} else {
|
||||
|
||||
*error_msg = apr_psprintf(msr->mp, "A Request body is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_limit);
|
||||
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
if (buflen != 0) {
|
||||
int rcbs = modsecurity_request_body_store(msr, buf, buflen, error_msg);
|
||||
if (rcbs < 0) {
|
||||
if (rcbs == -5) {
|
||||
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
|
||||
return -5;
|
||||
} else if ((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
|
||||
|
||||
} else if ((msr->txcfg->is_enabled == MODSEC_DETECTION_ONLY) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)) {
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
|
||||
} else {
|
||||
*error_msg = apr_psprintf(msr->mp, "Request body no files data length is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_no_files_limit);
|
||||
if(msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)
|
||||
return -5;
|
||||
}
|
||||
}
|
||||
|
||||
if(msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)
|
||||
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT))
|
||||
return -1;
|
||||
if((msr->txcfg->is_enabled == MODSEC_DETECTION_ONLY) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -732,15 +732,21 @@ static int hook_request_late(request_rec *r) {
|
||||
/* Check request body limit (non-chunked requests only). */
|
||||
if (msr->request_content_length > msr->txcfg->reqbody_limit) {
|
||||
|
||||
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
|
||||
msr->inbound_error = 1;
|
||||
|
||||
if(msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT) {
|
||||
msr_log(msr, 1, "Request body (Content-Length) is larger than the "
|
||||
"configured limit (%ld). Deny with status (%d)", msr->txcfg->reqbody_limit, HTTP_REQUEST_ENTITY_TOO_LARGE);
|
||||
return HTTP_REQUEST_ENTITY_TOO_LARGE;
|
||||
} else {
|
||||
} else if ((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)){
|
||||
msr->inbound_error = 1;
|
||||
msr_log(msr, 1, "Request body (Content-Length) is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_limit);
|
||||
} else if ((msr->txcfg->is_enabled == MODSEC_DETECTION_ONLY) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_PARTIAL)){
|
||||
msr->inbound_error = 1;
|
||||
} else {
|
||||
msr_log(msr, 1, "A Request body (Content-Length) is larger than the "
|
||||
"configured limit (%ld).", msr->txcfg->reqbody_limit);
|
||||
msr->inbound_error = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -771,7 +777,7 @@ static int hook_request_late(request_rec *r) {
|
||||
break;
|
||||
case -5 : /* Request body limit reached. */
|
||||
msr->inbound_error = 1;
|
||||
if(msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT) {
|
||||
if((msr->txcfg->is_enabled == MODSEC_ENABLED) && (msr->txcfg->if_limit_action == REQUEST_BODY_LIMIT_ACTION_REJECT)) {
|
||||
r->connection->keepalive = AP_CONN_CLOSE;
|
||||
if (my_error_msg != NULL) {
|
||||
msr_log(msr, 1, "%s. Deny with code (%d)", my_error_msg, HTTP_REQUEST_ENTITY_TOO_LARGE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user