diff options
author | 2020-05-10 13:28:32 -0700 | |
---|---|---|
committer | 2020-05-11 12:03:10 -0700 | |
commit | b366d655af0e0f5a9ff3e053a693838d49884ea2 (patch) | |
tree | 98843ce127f4a02a1073d0c4d873b3c7fa69c488 | |
parent | Merge pull request #924 from python-discord/feature/hemlock/perma-ban-overrid... (diff) |
Token remover: catch ValueError when non-ASCII chars are present
The token uses base64 and base64 only allows ASCII characters. Thus, if
a match has non-ASCII characters, it's not a valid token. Catching the
ValueError is simpler than trying to adjust the regex to only match
valid base64.
Fixes #928
Fixes BOT-3X
-rw-r--r-- | bot/cogs/token_remover.py | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bot/cogs/token_remover.py b/bot/cogs/token_remover.py index 6721f0e02..860ae9f3a 100644 --- a/bot/cogs/token_remover.py +++ b/bot/cogs/token_remover.py @@ -135,7 +135,7 @@ class TokenRemover(Cog): try: content: bytes = base64.b64decode(b64_content) return content.decode('utf-8').isnumeric() - except (binascii.Error, UnicodeDecodeError): + except (binascii.Error, ValueError): return False @staticmethod @@ -150,7 +150,7 @@ class TokenRemover(Cog): try: content = base64.urlsafe_b64decode(b64_content) snowflake = struct.unpack('i', content)[0] - except (binascii.Error, struct.error): + except (binascii.Error, struct.error, ValueError): return False return snowflake_time(snowflake + TOKEN_EPOCH) < DISCORD_EPOCH_TIMESTAMP |