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
This commit is contained in:
Valentin Lorentz 2024-07-19 16:41:12 +02:00
parent 54f7b5a5b6
commit 917e3019bc
2 changed files with 10 additions and 5 deletions

View File

@ -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')

View File

@ -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