Browse Source

Validate nickname against RFC 2812 rules

master
JustAnotherArchivist 2 years ago
parent
commit
619089f071
1 changed files with 6 additions and 2 deletions
  1. +6
    -2
      http2irc.py

+ 6
- 2
http2irc.py View File

@@ -115,8 +115,12 @@ class Config(dict):
if obj['irc']['family'] not in ('inet', 'INET', 'inet6', 'INET6'):
raise InvalidConfig('Invalid IRC family')
obj['irc']['family'] = getattr(socket, f'AF_{obj["irc"]["family"].upper()}')
if 'nick' in obj['irc'] and not isinstance(obj['irc']['nick'], str): #TODO: Check whether it's a valid nickname
raise InvalidConfig('Invalid IRC nick')
if 'nick' in obj['irc']:
if not isinstance(obj['irc']['nick'], str) or not obj['irc']['nick']:
raise InvalidConfig('Invalid IRC nick')
if obj['irc']['nick'][0] not in string.ascii_letters + '[]\\`_^{|}' or obj['irc']['nick'].strip(string.ascii_letters + string.digits + '[]\\`_^{|}') != '':
# The allowed characters in nicknames (per RFC 2812) are a strict subset of the ones for usernames, so no need to also check for the latter.
raise InvalidConfig('Invalid IRC nick: contains illegal characters')
if len(IRCClientProtocol.nick_command(obj['irc']['nick'])) > 510:
raise InvalidConfig('Invalid IRC nick: NICK command too long')
if 'real' in obj['irc'] and not isinstance(obj['irc']['real'], str):


Loading…
Cancel
Save