Skip to content

Commit 6ec8fd9

Browse files
committed
Fixed auditlog in case of internal redirect
1 parent c0ae166 commit 6ec8fd9

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/ngx_http_modsecurity_common.h

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct {
8080
unsigned waiting_more_body:1;
8181
unsigned body_requested:1;
8282
unsigned processed:1;
83+
unsigned logged:1;
8384
} ngx_http_modsecurity_ctx_t;
8485

8586

src/ngx_http_modsecurity_log.c

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ ngx_http_modsecurity_log_handler(ngx_http_request_t *r)
6767
return NGX_ERROR;
6868
}
6969

70+
if (ctx->logged) {
71+
dd("already logged earlier");
72+
return NGX_OK;
73+
}
74+
7075
dd("calling msc_process_logging for %p", ctx);
7176
old_pool = ngx_http_modsecurity_pcre_malloc_init(r->pool);
7277
msc_process_logging(ctx->modsec_transaction);

src/ngx_http_modsecurity_module.c

+10
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,16 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
137137
intervention.url = NULL;
138138
intervention.log = NULL;
139139
intervention.disruptive = 0;
140+
ngx_http_modsecurity_ctx_t *ctx = NULL;
140141

141142
dd("processing intervention");
142143

144+
ctx = ngx_http_get_module_ctx(r, ngx_http_modsecurity_module);
145+
if (ctx == NULL)
146+
{
147+
return NGX_HTTP_INTERNAL_SERVER_ERROR;
148+
}
149+
143150
if (msc_intervention(transaction, &intervention) == 0) {
144151
dd("nothing to do");
145152
return 0;
@@ -194,6 +201,9 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
194201

195202
if (intervention.status != 200)
196203
{
204+
ngx_http_modsecurity_log_handler(r);
205+
ctx->logged = 1;
206+
197207
if (r->header_sent)
198208
{
199209
dd("Headers are already sent. Cannot perform the redirection at this point.");

0 commit comments

Comments
 (0)