Overview
src/collaboration/collaboration.gateway.ts has @WebSocketGateway with no guards applied. Any WebSocket client that can reach the server can join any collaboration session by knowing the session ID, without any identity or authorization check. This is effectively unauthenticated write access to shared document state.
Specifications
Features:
- Validate a JWT passed in the WebSocket handshake query string or
Authorization header before the connection is accepted.
- Reject connections with invalid or missing tokens.
Tasks:
- Create
WsJwtAuthGuard that reads socket.handshake.auth.token or query ?token=.
- Verify the JWT using the same
JwtService used for REST routes.
- Apply the guard via
@UseGuards(WsJwtAuthGuard) on the gateway class.
- Store the verified user in
socket.data.user for downstream use.
- Add integration tests for rejected and accepted WebSocket connections.
Impacted Files:
src/collaboration/collaboration.gateway.ts
- New
src/collaboration/guards/ws-jwt-auth.guard.ts
Acceptance Criteria
- WebSocket connection without valid JWT is rejected during handshake.
- Authenticated user identity is available in all message handlers via
socket.data.user.
- Integration test covers both anonymous and authenticated connection scenarios.
Overview
src/collaboration/collaboration.gateway.tshas@WebSocketGatewaywith noguardsapplied. Any WebSocket client that can reach the server can join any collaboration session by knowing the session ID, without any identity or authorization check. This is effectively unauthenticated write access to shared document state.Specifications
Features:
Authorizationheader before the connection is accepted.Tasks:
WsJwtAuthGuardthat readssocket.handshake.auth.tokenor query?token=.JwtServiceused for REST routes.@UseGuards(WsJwtAuthGuard)on the gateway class.socket.data.userfor downstream use.Impacted Files:
src/collaboration/collaboration.gateway.tssrc/collaboration/guards/ws-jwt-auth.guard.tsAcceptance Criteria
socket.data.user.