RuView icon indicating copy to clipboard operation
RuView copied to clipboard

fix: restrict WebSocket client-disconnect endpoint to admins (V-003)

Open PrinceAudre opened this issue 4 months ago • 0 comments

Summary

Alternative fix for V-003 (DELETE /clients/{client_id} authorization) — see the discussion on #1392.

disconnect_client in archive/v1/src/api/routers/stream.py required authentication but no authorization, so any authenticated user could disconnect any WebSocket client by id.

Why not per-client ownership

#1392 adds an ownership check comparing client_info["user_id"] to the caller. But WebSocket connections carry no user identity:

  • ConnectionManager.connect() records only a random uuid4 — no user.
  • WebSocketConnection.get_info() exposes no user_id.
  • get_connected_clients() returns those info dicts.

So client_info.get("user_id") is always None, and None != current_user["id"] is always true — the check returns 403 to everyone and breaks the endpoint for all callers, admins included. Per-connection ownership isn't possible until WS auth (#1396 / #1400) records a user at connect time.

This fix

Gate the endpoint on admin using the existing get_admin_user dependency (already used across dependencies.py). This is a destructive operator action, so admin-only is appropriate; it closes V-003 and keeps the endpoint working for operators.

-    current_user: Dict = Depends(require_auth)
+    current_user: Dict = Depends(get_admin_user)

Test

Adds archive/v1/tests/integration/test_stream_disconnect_authz.py, which asserts the authorization property (the actual vulnerability): non-admin → 403 (disconnect never called), admin → 200, admin + unknown client → 404.

Note

This intentionally narrows the endpoint to admins — ordinary authenticated users can no longer disconnect clients, since connections have no owner to scope against. If per-user WS auth lands (#1396 / #1400), this can broaden to "owner or admin".

🤖 Generated with Claude Code

PrinceAudre avatar Jul 25 '26 11:07 PrinceAudre