From 917e3019bcefee6afad18dd08f8e19b914bb9749 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Fri, 19 Jul 2024 16:41:12 +0200 Subject: [PATCH] Fall back to banning host instead of exact mask This only happens on the newly introduced account extban (in case the user does not have an account, or the server does not provide accounts) so this does not change existing behavior. Falling back to the host instead of the exact mask makes it less easy to evade these bans --- plugins/Channel/test.py | 8 ++++---- src/conf.py | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/plugins/Channel/test.py b/plugins/Channel/test.py index aa11982eb..48f3efe51 100644 --- a/plugins/Channel/test.py +++ b/plugins/Channel/test.py @@ -245,9 +245,9 @@ class ChannelTestCase(ChannelPluginTestCase): '*!user@host.domain.tld') join() with conf.supybot.protocols.irc.banmask.context(['account']): - # falls back from --account to config, then to exact hostmask + # falls back from --account to config, then to only the host self.assertKban('kban --account foobar', - 'foobar!user@host.domain.tld') + '*!*@host.domain.tld') join() self.assertKban('kban --account --host foobar', '*!*@host.domain.tld') @@ -277,9 +277,9 @@ class ChannelTestCase(ChannelPluginTestCase): '*!user@host.domain.tld') join() with conf.supybot.protocols.irc.banmask.context(['account']): - # falls back from --account to config, then to exact hostmask + # falls back from --account to config, then to only the host self.assertKban('kban --account foobar', - 'foobar!user@host.domain.tld') + '*!*@host.domain.tld') join() self.assertKban('kban --account --host foobar', '*!*@host.domain.tld') diff --git a/src/conf.py b/src/conf.py index ed5c7d4d8..f090816b3 100644 --- a/src/conf.py +++ b/src/conf.py @@ -1316,7 +1316,12 @@ class Banmask(registry.SpaceSeparatedSetOfStrings): if (bnick, buser, bhost) == ('*', '*', '*') and \ ircutils.isUserHostmask(hostmask) and \ not masks: - masks.append(hostmask) + # still no ban mask found, fallback to the host, if any + if host != '*': + masks.append(ircutils.joinHostmask('*', '*', host)) + else: + # if no host, fall back to the exact mask provided + masks.append(hostmask) return masks