From c9176a06fcb732ac3c209e7c03f9ec14a3ae0f17 Mon Sep 17 00:00:00 2001 From: James Lu Date: Wed, 20 Mar 2019 21:08:21 -0700 Subject: [PATCH] relay: check for nicks starting with numbers or - after removing Unicode --- plugins/relay.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/plugins/relay.py b/plugins/relay.py index 6c2fc3b..1131d13 100644 --- a/plugins/relay.py +++ b/plugins/relay.py @@ -191,12 +191,24 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''): separator = separator.replace('/', FALLBACK_SEPARATOR) nick = nick.replace('/', FALLBACK_SEPARATOR) - if nick.startswith(tuple(string.digits+'-')): + # Loop over every character in the nick, making sure that it only contains valid + # characters. + if not is_unicode_capable: + nick = _sanitize(nick) + else: + # UnrealIRCd 4's forbidden nick chars, from + # https://github.com/unrealircd/unrealircd/blob/02d69e7d8/src/modules/charsys.c#L152-L163 + for char in """!+%@&~#$:'\"?*,.""": + nick = nick.replace(char, FALLBACK_CHARACTER) + + if nick.startswith(tuple(string.digits)): # On TS6 IRCds, nicks that start with 0-9 are only allowed if # they match the UID of the originating server. Otherwise, you'll # get nasty protocol violation SQUITs! - # Nicks starting with - are likewise not valid. nick = '_' + nick + elif nick.startswith('-'): + # Nicks starting with - are likewise not valid. + nick = '_' + nick[1:] # Maximum allowed length that relay nicks may have, minus the /network tag if used. allowedlength = maxnicklen @@ -214,16 +226,6 @@ def normalize_nick(irc, netname, nick, times_tagged=0, uid=''): if times_tagged >= 1: nick += suffix - # Loop over every character in the nick, making sure that it only contains valid - # characters. - if not is_unicode_capable: - nick = _sanitize(nick) - else: - # UnrealIRCd 4's forbidden nick chars, from - # https://github.com/unrealircd/unrealircd/blob/02d69e7d8/src/modules/charsys.c#L152-L163 - for char in """!+%@&~#$:'\"?*,.""": - nick = nick.replace(char, FALLBACK_CHARACTER) - while irc.nick_to_uid(nick) not in (None, uid): # The nick we want exists: Increase the separator length by 1 if the user was already # tagged, but couldn't be created due to a nick conflict. This can happen when someone