Enforce Socket.IO Room and Event Authorization
Apply server-side Socket.IO identity, room and event checks with expiry and recovered-connection tests.
List namespaces, room types and events that expose protected data or change application state. For each, record how the connection is authenticated, what grants access, and which failures can be shared with the client. Start with a fixture workspace room where members can receive updates and only editors can publish. Use a second workspace with similar room labels to detect accidental cross-tenant behavior. ## Key Points - [Socket.IO middleware](https://socket.io/docs/v4/middlewares) - [Socket.IO connection state recovery](https://socket.io/docs/v4/connection-state-recovery) - [Socket.IO server API](https://socket.io/docs/v4/server-api/) - [Socket.IO 4.8.1 socket implementation](https://github.com/socketio/socket.io/blob/91e1c8b3584054db6072046404a24e79a17c1367/packages/socket.io/lib/socket.ts) - [Socket.IO 4.8.1 namespace implementation](https://github.com/socketio/socket.io/blob/91e1c8b3584054db6072046404a24e79a17c1367/packages/socket.io/lib/namespace.ts)
skilldb get websocket-skills/socketio-authenticationFull skill: 33 linesEnforce Socket.IO Room and Event Authorization
Map identities and actions
List namespaces, room types and events that expose protected data or change application state. For each, record how the connection is authenticated, what grants access, and which failures can be shared with the client. Start with a fixture workspace room where members can receive updates and only editors can publish. Use a second workspace with similar room labels to detect accidental cross-tenant behavior.
Use connection middleware to verify the supported credential during the handshake and associate the server-established identity with the socket. Treat every payload as untrusted, including room names, user IDs and role claims. Validate shape and size before handling it. Use server-side records to decide the allowed tenant and room. A successful connection does not authorize every room or event.
Enforce current rights
Before a join, look up the server-side membership and derive the room identifier within its tenant namespace. Check the permissions required by individual events, including events that write records or broadcast messages. Room membership can be useful routing state while the authoritative store controls access. Return safe acknowledgments and avoid broadcasting on a failed check. Keep token and protected payload values out of logs.
Decide how expiry, logout and revocation apply to a long-lived socket. Use a mechanism that revalidates at the required boundary, and leave or disconnect sockets whose access was removed. Check what the configured adapter and Socket.IO version restore on a recovered socket. Review the installed implementation as well as the middleware configuration. In the documented 4.8.1 source, the socket constructor restores session state and queues missed packets before the namespace runs middleware. Setting skipMiddlewares to false alone cannot establish that revoked clients receive no protected replay. Disable built-in recovery on a server carrying protected payloads unless the design independently authorizes replay before any packet can leave. Use explicit application replay that rechecks current rights or a separate server for protected traffic.
Test clients with different rights
Build fixtures for two users, two rooms, and both allowed and denied events. Assert what each client actually receives, not only the sender's acknowledgment. Try an unauthorized room identifier and confirm no membership or write changed. Remove access while the client is disconnected, then test reconnection through the supported recovery window. Inspect authorized fixture transport packets or server emission evidence to verify absence of protected payloads, alongside checking client callbacks. Exercise session expiry and a normal fresh reconnect too.
Record server, client and adapter versions and whether each test used recovery. Include the expected broadcast recipients, acknowledgments, and stored state. Keep deployed adapter behavior as an open check until it is tested on the intended topology.
References
Install this skill directly: skilldb add websocket-skills
Related Skills
Websocket Basics
WebSocket API fundamentals including connection lifecycle, message framing, and browser/server implementations
Chat Rooms
Chat room architecture covering message routing, history, moderation, and scalable room-based real-time systems
Collaborative Editing
Real-time collaborative editing with CRDTs and Operational Transform for conflict-free concurrent document editing
Presence
User presence system design for tracking online/offline status, typing indicators, and activity in real-time apps
Reconnection
Reconnection and offline resilience patterns for WebSocket apps including retry strategies and state synchronization
Scaling Websockets
Scaling WebSocket applications with Redis pub/sub, sticky sessions, horizontal scaling, and load balancing strategies