Skip to content

fix(server): verify session/machine ownership at websocket connection time#784

Open
ex3ndr-bot wants to merge 2 commits intoslopus:mainfrom
ex3ndr-bot:fix/761-agent-websocket-session-claim
Open

fix(server): verify session/machine ownership at websocket connection time#784
ex3ndr-bot wants to merge 2 commits intoslopus:mainfrom
ex3ndr-bot:fix/761-agent-websocket-session-claim

Conversation

@ex3ndr-bot
Copy link

Summary

This PR fixes issue #761 where happy-agent send fails because the agent.key token lacks a session claim that the websocket connection requires.

Problem

  • Terminal auth (/v1/auth/request) creates tokens WITH session claims: { session: answer.id }
  • Account auth (/v1/auth/account/request) creates tokens WITHOUT session claims
  • happy-agent uses account auth, so its tokens don't have session claims
  • While the websocket didn't explicitly require session claims in the JWT, proper authorization validation was missing

Solution

Instead of requiring session claims in the JWT (which wouldn't make sense for account-scoped tokens), we now verify session/machine ownership via database lookup at websocket connection time.

Changes

  1. Added db import to socket.ts
  2. For session-scoped connections: verify the session belongs to the authenticated user via DB lookup
  3. For machine-scoped connections: verify the machine belongs to the authenticated user via DB lookup

This approach:

  • ✅ Allows account tokens (from /v1/auth/account/request) to work with session-scoped connections
  • ✅ Maintains security by verifying the session belongs to the authenticated user
  • ✅ Adds consistent validation for machine-scoped connections as well
  • ✅ Rejects unauthorized connections early, before any handlers are registered

Testing

The fix adds proper authorization checks at the websocket connection layer. The existing tests for session operations (which verify accountId: userId) continue to provide defense in depth.

Daycare Agent added 2 commits February 28, 2026 04:56
Moves the following packages from dependencies to devDependencies:
- @types/cross-spawn
- @types/http-proxy
- @types/ps-list
- @types/qrcode-terminal
- @types/react
- @types/tmp

Fixes slopus#766
… time

Fixes slopus#761: happy-agent send fails due to missing session claim in JWT

The issue was that account tokens (used by happy-agent) don't have session claims,
but the websocket should still work for session-scoped connections.

Instead of requiring session claims in the JWT, we now verify session/machine
ownership via database lookup at connection time. This approach:

1. Allows account tokens (from /v1/auth/account/request) to work with session-scoped connections
2. Maintains security by verifying the session belongs to the authenticated user
3. Adds consistent validation for machine-scoped connections as well

The verification happens early in the connection flow, rejecting unauthorized
connections before any handlers are registered.
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