Skip to content

Commit

Permalink
nginx: Considering modsec state before apply any rules
Browse files Browse the repository at this point in the history
For some reason the state of modsec (enable, disable or detecting only) was not
being checked under certain circumstances. For instance, while reading the
body. This was leading ModSecurity to fail and consequently nginx. This patch
added the to standalone implementation mechanism to verify the state that is now
verified under the nginx module.
  • Loading branch information
Felipe Zimmerle committed Jan 14, 2014
1 parent 9bf1f6a commit fe14d9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions nginx/modsecurity/ngx_http_modsecurity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,10 @@ ngx_http_modsecurity_handler(ngx_http_request_t *r)
return rc;
}

if (modsecContextState(ctx->req) == MODSEC_DISABLED) {
return NGX_DECLINED;
}

if (r->method == NGX_HTTP_POST
&& modsecIsRequestBodyAccessEnabled(ctx->req) ) {

Expand Down
11 changes: 11 additions & 0 deletions standalone/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,16 @@ void modsecSetConfigForIISRequestBody(request_rec *r)
msr->txcfg->stream_inbody_inspection = 1;
}

int modsecContextState(request_rec *r)
{
modsec_rec *msr = retrieve_msr(r);

if(msr == NULL || msr->txcfg == NULL)
return NOT_SET;

return msr->txcfg->is_enabled;
}

int modsecIsRequestBodyAccessEnabled(request_rec *r)
{
modsec_rec *msr = retrieve_msr(r);
Expand Down Expand Up @@ -681,3 +691,4 @@ void modsecSetDropAction(int (*func)(request_rec *r)) {
const char *modsecIsServerSignatureAvailale(void) {
return new_server_signature;
}

2 changes: 2 additions & 0 deletions standalone/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void modsecSetDropAction(int (*func)(request_rec *r));
int modsecIsResponseBodyAccessEnabled(request_rec *r);
int modsecIsRequestBodyAccessEnabled(request_rec *r);

int modsecContextState(request_rec *r);

void modsecSetConfigForIISRequestBody(request_rec *r);

const char *modsecIsServerSignatureAvailale(void);
Expand Down

0 comments on commit fe14d9d

Please sign in to comment.