File: app/api/websocket.py
Line: ~12
Description:
The WebSocket endpoint @router.websocket("/ws/{user_id}") accepts connections without validating any authentication token or session. Any user (or unauthenticated attacker) who knows or can guess a user_id can connect to that user's WebSocket stream. This allows connection spoofing and potentially leaks sensitive real-time watch activity, download progress, and recommendation events.
Impact: High (Security/Privacy issue). Allows unauthorized viewing of user activity.
Suggested Fix:
- Require a
token query parameter during the WebSocket connection handshake.
- Validate the token against the active sessions (e.g., using
validate_token()).
- Reject the connection (
await websocket.close(code=1008)) if the token is missing or invalid.