[kimi] Add WebSocket authentication for Matrix connections (#682) #744

Merged
kimi merged 1 commits from kimi/issue-682 into main 2026-03-21 16:14:06 +00:00
Collaborator

Fixes #682

Summary

Added token-based authentication to the WebSocket endpoints used by the Matrix.

Changes

  • src/config.py: Added matrix_ws_token setting for WebSocket auth token
  • src/dashboard/routes/world.py: Added _authenticate_ws() helper function that:
    • Validates token from query param (?token=) or first message ({type: auth, token: ...})
    • Closes connection with code 4001 on invalid/missing token
    • Sends connection_ack message after successful authentication
    • Auth is disabled when matrix_ws_token is empty (dev mode)
  • tests/dashboard/test_world_api.py: Added comprehensive tests for WS auth scenarios

Acceptance Criteria

  • WS connections must send token in first message or as query param ?token=
  • If matrix_ws_token is empty/unset, auth is disabled (dev mode)
  • Invalid token gets WebSocket close with code 4001
  • Valid token gets connection_ack message back
  • Existing /api/world/ws behavior unchanged when token not configured
  • tox -e unit passes
  • tox -e lint passes
Fixes #682 ## Summary Added token-based authentication to the WebSocket endpoints used by the Matrix. ## Changes - **src/config.py**: Added `matrix_ws_token` setting for WebSocket auth token - **src/dashboard/routes/world.py**: Added `_authenticate_ws()` helper function that: - Validates token from query param (`?token=`) or first message (`{type: auth, token: ...}`) - Closes connection with code 4001 on invalid/missing token - Sends `connection_ack` message after successful authentication - Auth is disabled when `matrix_ws_token` is empty (dev mode) - **tests/dashboard/test_world_api.py**: Added comprehensive tests for WS auth scenarios ## Acceptance Criteria - [x] WS connections must send token in first message or as query param ?token= - [x] If matrix_ws_token is empty/unset, auth is disabled (dev mode) - [x] Invalid token gets WebSocket close with code 4001 - [x] Valid token gets connection_ack message back - [x] Existing /api/world/ws behavior unchanged when token not configured - [x] tox -e unit passes - [x] tox -e lint passes
kimi added 1 commit 2026-03-21 15:23:06 +00:00
feat: add WebSocket authentication for Matrix connections
Some checks failed
Tests / lint (pull_request) Has been cancelled
Tests / test (pull_request) Has been cancelled
2b102be69a
- Add matrix_ws_token setting to config.py for token-based WS auth
- Add _authenticate_ws() helper to validate tokens in world.py
- Support token via query param (?token=) or first message ({type: auth})
- Close connection with code 4001 on invalid/missing token
- Send connection_ack message after successful authentication
- Auth disabled when matrix_ws_token is empty (dev mode)
- Add comprehensive tests for WS auth scenarios

Fixes #682
kimi force-pushed kimi/issue-682 from 2b102be69a to 41b0dc58b5 2026-03-21 16:13:47 +00:00 Compare
kimi merged commit 815933953c into main 2026-03-21 16:14:06 +00:00
kimi deleted branch kimi/issue-682 2026-03-21 16:14:06 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#744