-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix Firefox WebSocket crash by adding error handling to SocketHandler Issue#942 #943
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -217,3 +217,25 @@ def load_user_settings(self): | |||||||||||||||||||||||||||||||||||||||||||
settings["user_css"] = user_css | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
return settings | ||||||||||||||||||||||||||||||||||||||||||||
class SocketHandler(tornado.websocket.WebSocketHandler): | ||||||||||||||||||||||||||||||||||||||||||||
def check_origin(self, origin): | ||||||||||||||||||||||||||||||||||||||||||||
return True # Or customize for security | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+221
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Allowing all origins in check_origin may introduce security risks. Disabling origin checks exposes the WebSocket to CSRF and similar attacks. Restrict allowed origins or make this configurable for production. |
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def open(self): | ||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||
logging.info("WebSocket connection opened") | ||||||||||||||||||||||||||||||||||||||||||||
# Existing open logic (e.g., register client) | ||||||||||||||||||||||||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||
logging.error(f"WebSocket open error: {e}") | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def on_message(self, message): | ||||||||||||||||||||||||||||||||||||||||||||
try: | ||||||||||||||||||||||||||||||||||||||||||||
# Existing message handling logic | ||||||||||||||||||||||||||||||||||||||||||||
pass | ||||||||||||||||||||||||||||||||||||||||||||
except Exception as e: | ||||||||||||||||||||||||||||||||||||||||||||
logging.error(f"WebSocket message error: {e}") | ||||||||||||||||||||||||||||||||||||||||||||
self.close() # Gracefully close on error | ||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+231
to
+237
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Closing the WebSocket on any message error may be overly aggressive. Consider handling exceptions more selectively, logging non-critical errors, and only closing the connection for serious issues.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
def on_close(self): | ||||||||||||||||||||||||||||||||||||||||||||
logging.info("WebSocket connection closed") | ||||||||||||||||||||||||||||||||||||||||||||
# Existing cleanup logic |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: Early return from the function bypasses the original scatter logic.
If the early return is intentional, remove the unreachable scatter logic below. Otherwise, clarify when each path should be used.