Skip to content

Commit cd3f904

Browse files
committed
Ensure that proper intervention response code gets into audit log
in case of internal redirects due to e.g. error_page
1 parent a76a0c9 commit cd3f904

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

Diff for: src/ngx_http_modsecurity_module.c

+5-4
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ ngx_http_modsecurity_process_intervention (Transaction *transaction, ngx_http_re
208208
if (intervention.status != 200)
209209
{
210210
/**
211-
* FIXME: this one will call msc_process_logging() but code may be
212-
* 200 instead of 403 by some reason.
211+
* FIXME: this will bring proper response code to audit log in case
212+
* when e.g. error_page redirect was triggered, but there still won't be another
213+
* required pieces like response headers etc.
213214
*
214215
*/
215-
r->err_status = intervention.status;
216-
r->headers_out.status = intervention.status;
216+
msc_update_status_code(ctx->modsec_transaction, intervention.status);
217+
217218
dd("intervention -- calling log handler manually with code: %d", intervention.status);
218219
ngx_http_modsecurity_log_handler(r);
219220
ctx->logged = 1;

Diff for: tests/modsecurity-config-custom-error-page.t

-5
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,9 @@ like($t4, qr/$index_txt/, 'ModSecurity at server / other');
157157
like($global, qr/what=root/, 'ModSecurity at server / root present in auditlog');
158158
unlike($global, qr/what=other/, 'ModSecurity at server / other not present in auditlog');
159159

160-
TODO: {
161-
local $TODO = 'not yet';
162-
163160
like($local, qr/Access denied with code 403/, 'ModSecurity at location / 403 in auditlog');
164161
like($global, qr/Access denied with code 403/, 'ModSecurity at server / 403 in auditlog');
165162

166-
}
167-
168163
###############################################################################
169164

170165
sub http_get_host {

0 commit comments

Comments
 (0)