Skip to content

Support log reopen on SIGHUP and SIGUSR1#372

Open
fremail wants to merge 1 commit into
owasp-modsecurity:masterfrom
fremail:add/log-reopen
Open

Support log reopen on SIGHUP and SIGUSR1#372
fremail wants to merge 1 commit into
owasp-modsecurity:masterfrom
fremail:add/log-reopen

Conversation

@fremail
Copy link
Copy Markdown

@fremail fremail commented Mar 24, 2026

This PR uses new ModSecurity API implemented in owasp-modsecurity/ModSecurity#3521

The CI build fails because the ModSecurity API isn't released yet ☝️

There is another PR with a similar code -- #198 -- but its code is outdated and uses a different API. In any case this PR is based on work in #198, so thank you @brandonpayton for the initial work on that.

I've tested the code using testing notes from #198. I hope we'll see these changes released soon!

Side notes for reviewers

msc_rules_reopen_logs() only exists in rules_set.h (the newer API) — it's not available in the older rules.h at all. So the ``#ifdef MSC_USE_RULES_SET` guard is necessary. Without it the build would fail against older
libmodsecurity versions that don't have this function.

Links

This PR depends on code from owasp-modsecurity/ModSecurity#3521
Resolves #121
Similar PR #198

`msc_rules_reopen_logs()` only exists in rules_set.h (the newer API) — it's not available in the older rules.h at all. So the ``#ifdef MSC_USE_RULES_SET` guard is necessary here; without it, the build would fail against older
  libmodsecurity versions that don't have this function.
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for reopening ModSecurity audit/debug logs when nginx handles log reopen/reload signals (SIGUSR1/SIGHUP), using the newer msc_rules_reopen_logs() ModSecurity API behind an MSC_USE_RULES_SET feature guard.

Changes:

  • Registers a custom ngx_open_file_t flush callback to trigger ModSecurity log reopen on nginx log reopen events.
  • Tracks each merged RulesSet * so log reopen can be applied across all configured rulesets.
  • Extends main module configuration to store the reopen trigger file handle.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/ngx_http_modsecurity_module.c Adds log-reopen trigger setup, ruleset registration, and a flush callback calling msc_rules_reopen_logs() on reopen signals.
src/ngx_http_modsecurity_common.h Extends main конф struct to hold the reopen trigger ngx_open_file_t *.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +678 to +697
#if defined(MSC_USE_RULES_SET)
/* Set up log reopening on SIGUSR1/SIGHUP */
{
ngx_str_t log_reopen_file = ngx_string("/dev/null");

conf->log_reopen = ngx_conf_open_file(cf->cycle, &log_reopen_file);
if (conf->log_reopen == NULL) {
dd("failed to open file for triggering log reopen");
return NGX_CONF_ERROR;
}

conf->log_reopen->data = ngx_list_create(cf->pool, 100,
sizeof(RulesSet *));
if (conf->log_reopen->data == NULL) {
dd("failed to create list of rules sets for log reopen");
return NGX_CONF_ERROR;
}

conf->log_reopen->flush = ngx_http_modsecurity_log_reopen;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

reopen audit log on SIGUSR1 and SIGHUP

2 participants