Skip to content

[INVESTIGATE] sec: voice WebSocket missing ownership check — JWT signature validated but session.user_id never compared #600

Closed

Description

@pavshulin

Marker: INVESTIGATE — finding from /security-review on PR #599 (2026-04-30). Validated at confidence 9/10. NOT a regression from #590; the gap was introduced by #581 ("voice tool calls + canvas orb", commit 7d8abe8) when it merged to dev. Filing here so it doesn't get lost.

Summary

The /ws/voice/{voice_session_id} WebSocket validates the JWT signature but never checks that the JWT's user owns the referenced voice session. Any platform-authenticated user holding a valid JWT can connect to any active voice session whose 128-bit voice_session_id they observe (logs, browser network tab, XSS-readable window.location, etc.).

Once connected, the attacker can:

  • Eavesdrop on the victim's outbound audio + live transcripts
  • Inject audio that gets transcribed and persisted to the victim's chat history under the victim's user_id
  • Trigger tool calls audit-logged with actor_id=<victim's id>, actor_email=<victim's email> — i.e. attributed to the victim

CVSS estimate: 6.5–7.0 (AV:N / AC:H / PR:L / UI:N / C:H / I:H / A:N) — high attack complexity because the 128-bit session id is the de-facto access gate, but the impact when leaked is full session impersonation including misattribution of actions.

Code evidence

src/backend/routers/voice.py — voice_websocket handler:

@router.websocket("/ws/voice/{voice_session_id}")
async def voice_websocket(
    websocket: WebSocket,
    voice_session_id: str,
    token: str = Query(default=None),
):
    session = voice_service.get_session(voice_session_id)
    if not session:
        await websocket.close(code=4004, reason="Voice session not found")
        return

    if token:
        from jose import jwt, JWTError
        from config import SECRET_KEY, ALGORITHM
        try:
            jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])  # ← payload discarded
        except JWTError:
            await websocket.close(code=4001, reason="Invalid token")
            return
    else:
        await websocket.close(code=4001, reason="Authentication required")
        return

    await websocket.accept()

What's missing:

  1. jwt.decode() is called and the result is thrown away — sub is never extracted
  2. No db.get_user_by_username(...) lookup
  3. session.user_id is never compared against the JWT's user

Exploit chain

  1. Victim Alice initiates a voice session via POST /api/agents/alice-agent/voice/start. Response returns voice_session_id = vs_<22-char token>. The id is also written to backend INFO logs and lives in Alice's browser scope.
  2. Attacker Bob (any authenticated platform user, including a user-role account that owns no agents) obtains the id via:
    • Backend log access (operator/admin)
    • XSS in any third-party tool Alice has open that can read window.location / Vue store state
    • Browser network inspection if Bob has shared-screen / pair-programming visibility
  3. Bob connects: wss://host/ws/voice/<vs_id>?token=<bob's JWT>. Server validates Bob's JWT signature, accepts the connection, never checks ownership.
  4. Bob has bidirectional access to Alice's voice session for the duration.

Adjacent finding (lower priority — defense in depth)

POST /api/agents/{name}/voice/stop (also in voice.py) uses Depends(get_authorized_agent) to gate access to the path agent ({name}), but the request.voice_session_id from the body is never cross-checked against the path agent or current_user.id. This means any user with access to ANY agent can pass any other user's voice_session_id and forcibly end + persist a transcript to that other user's session.

The security reviewer rejected this as exploitable on its own (requires the same prior leak of the 128-bit id), but it should be fixed in the same PR as the websocket handler — the cross-check pattern is identical.

Acceptance Criteria

  • /ws/voice/{voice_session_id} extracts sub from the decoded JWT, looks up the user, and rejects with WS close code 4003 if user.id != session.user_id
  • voice_stop looks up the session by id first, asserts session.agent_name == name AND session.user_id == current_user.id (or admin), and rejects with 403 otherwise
  • Unit test: WS handler rejects when JWT user != session owner
  • Unit test: voice_stop rejects body session_id that belongs to a different agent or user
  • Integration test: end-to-end attack chain returns 4003/403

Defense-in-depth follow-up (separate issue if not bundled)

Rotate /ws/voice/... to per-session ephemeral WS tickets — same single-use ticket pattern that #550 (/ws) and services/ws_ticket_service.py already implement. This means the session id alone is never sufficient to reach the WebSocket; the attacker would need a fresh ticket minted for them, which the ticket service won't do for a session they don't own.

References

Activity

  1. added
    priority-p1
    type-bug
    security
    severity-medium
    on Apr 30, 2026
  2. added
    status-in-progress
    on May 4, 2026
  3. self-assigned this
    on May 4, 2026
  4. added
    status-in-dev
    and removed
    status-in-progress
    on May 4, 2026
  5. added a commit that references this issue on Jun 1, 2026
  6. vybe commented on Jun 1, 2026

    @vybe
    Contributor

    Shipped in v0.6.0 (released via #998).

  7. removed
    status-in-dev
    on Jun 1, 2026
  8. added
    complexity-low
    theme-security
    on Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

complexity-lowpriority-p1securityseverity-mediumtheme-securitytype-bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions