Skip to content

fix: add JWT authentication to all WebSocket endpoints in live-service - #14

Merged
Senthil455 merged 1 commit into
mainfrom
fix/websocket-auth
Jun 15, 2026
Merged

fix: add JWT authentication to all WebSocket endpoints in live-service#14
Senthil455 merged 1 commit into
mainfrom
fix/websocket-auth

Conversation

@Senthil455

Copy link
Copy Markdown
Owner

Issue 5: Live Service WebSocket endpoints have zero authentication

Security - All three WebSocket endpoints were completely unauthenticated:

  • /ws/{channel} - anyone could connect and listen to all channels
  • /ws/chat - anyone could send messages
  • /ws/presence - anyone could send presence updates

The HTTP middleware (@app.middleware(http)) does not intercept WebSocket connections.

Fix

  • Added verify_ws_token() that validates a JWT before accepting any WebSocket connection
  • Token accepted via ?token= query parameter (frontend) or x-internal-auth header (service-to-service)
  • Uses existing INTERNAL_JWT_SECRET with HMAC-SHA256 verification
  • Invalid/expired/missing tokens get WebSocket close code 4001 with a reason message
  • All three endpoints now check auth before await websocket.accept()

Files changed

  • services/live-service/main.py - added verify_ws_token(), applied to all 3 WebSocket endpoints

- Created verify_ws_token() that validates JWT from query param or header
- WebSocket endpoints now reject unauthenticated connections with 4001
- Applies to /ws/{channel}, /ws/chat, and /ws/presence
- Uses existing INTERNAL_JWT_SECRET for token verification
- Accepts token via ?token= query parameter or x-internal-auth header
@Senthil455
Senthil455 merged commit c4bcacb into main Jun 15, 2026
1 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant