Skip to content

filter.d/nginx-botsearch: support the journal log format - #4223

Merged
sebres merged 1 commit into
fail2ban:masterfrom
VXNCXNX:fix/nginx-botsearch-journal
Aug 18, 2026
Merged

sebres merged 1 commit into
fail2ban:masterfrom
VXNCXNX:fix/nginx-botsearch-journal

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

nginx-botsearch misses every error-log line when nginx logs to the systemd journal, because its regex hardcodes the file-format prefix:

^ \[error\] \d+#\d+: \*\d+ 
$ fail2ban-regex '<journal line>' config/filter.d/nginx-botsearch.conf[logtype=journal]

before: Lines: 1 lines, 0 ignored, 0 matched, 1 missed
after:  Lines: 1 lines, 0 ignored, 1 matched, 0 missed

The plain file format still matches with the default logtype=file, 1 matched, 0 missed before and after.

The fix

nginx-error-common.conf and %(__prefix_line)s, which is exactly what gh-3646 (commit e03df480) did for nginx-forbidden, nginx-http-auth and nginx-limit-req. nginx-botsearch was simply left out of that pass.

On the other filter in the issue

gh-3732 names both nginx-bad-request.conf and nginx-botsearch.conf. I only changed the latter, deliberately: nginx-bad-request matches the access log (^<HOST> - \S+ \[\] "[^"]*" 400), which has no error-log prefix to parameterise, so __prefix_line does not apply to it. If you want journal support there it is a different change and I did not want to bundle a guess with a verified fix.

Verification

Two journal-format lines added to fail2ban/tests/files/logs/nginx-botsearch under # filterOptions: [{"logtype": "journal"}].

They are not invented. They are the file-format sample lines already in that file, re-prefixed with host nginx[2833]: , the same convention upstream used in nginx-http-auth:22 and nginx-limit-req:29.

With the filter change stashed and the new lines in place:

AssertionError: nginx-botsearch{'logtype': 'journal'}: True is not false : Line not matched when should have
on: fail2ban/tests/files/logs/nginx-botsearch:40
FAILED (failures=1)

Restored:

Ran 1 test in 0.008s
OK

fail2ban-testcases --no-network samples is 100 tests OK, and the full run is 541 tests OK (27 skipped, missing optional modules).

Disclosure: written with AI assistance (Claude Code). I ran fail2ban-regex for both logtypes myself, confirmed the file format still matches, and checked the journal prefix convention against the lines upstream already added.

The error-log regex hardcoded the file-format prefix, so lines carrying a
systemd journal prefix were missed. Use __prefix_line from
nginx-error-common.conf, as the other nginx error-log filters already do.

Closes gh-3732
@sebres
sebres merged commit 7bfc871 into fail2ban:master Aug 18, 2026
10 checks passed
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.

2 participants