Connect-time middleware
The connect handler is the natural place to run middleware: auth, version checks, geo-blocks, rate-limit registration. Raise ConnectionRefusedError(code, message) with a useful payload — Socket.IO surfaces both fields to the client's connect_error event.
Per-event rate limiting
Build a rate-limit decorator and apply it to the events that need it (chat sends, file uploads). Skip it on read-only events. Store windows keyed by sid; a small deque of timestamps per connection is enough.