From 3ef52eb59b2fdec07ae8c5cd99ce03caa89c9324 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 7 Mar 2024 19:51:32 -0800 Subject: [PATCH 1/2] Handle exceptions in chat mode's validate_username --- cli/onionshare_cli/web/chat_mode.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py index 5a11eedd..39899c65 100644 --- a/cli/onionshare_cli/web/chat_mode.py +++ b/cli/onionshare_cli/web/chat_mode.py @@ -48,13 +48,17 @@ class ChatModeWeb: self.define_routes() def validate_username(self, username): - username = username.strip() - return ( - username - and username.isascii() - and username not in self.connected_users - and len(username) < 128 - ) + try: + username = username.strip() + return ( + username + and username.isascii() + and username not in self.connected_users + and len(username) < 128 + ) + except Exception as e: + self.common.log("ChatModeWeb", "validate_username", e) + return False def define_routes(self): """ From 18bff0660c6d254be075e188c73fe9fa4e19144e Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 8 Mar 2024 09:40:43 -0800 Subject: [PATCH 2/2] Edit error message in ConnectionRefusedError error to be more generic --- cli/onionshare_cli/web/chat_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/onionshare_cli/web/chat_mode.py b/cli/onionshare_cli/web/chat_mode.py index 39899c65..514258b9 100644 --- a/cli/onionshare_cli/web/chat_mode.py +++ b/cli/onionshare_cli/web/chat_mode.py @@ -137,7 +137,7 @@ class ChatModeWeb: broadcast=True, ) else: - raise ConnectionRefusedError('You are active from another session!') + raise ConnectionRefusedError('Invalid session') @self.web.socketio.on("text", namespace="/chat") def text(message):