#1831·happy

Server: bearer tokens never expire and revocation is a no-op; RPC method rooms are not bound to the socket's scope

Author: ethicnology-agentCreated Sep 23, 2026Updated Sep 23, 2026

Two server-side defects, verified against 383c9f8b.

1. Tokens are unbounded in time and cannot be revoked. Tokens come from privacy-kit's createPersistentTokenGenerator (packages/happy-server/sources/app/auth/auth.ts:36), whose signing chain sets iat, nbf, iss and jti but never setExpirationTime; the verifier calls jwtVerify with no options, so no maximum age is enforced. invalidateToken / invalidateUserTokens (auth.ts:153) clear only the in-process 24h cache — the JWT stays cryptographically valid afterwards, and they are not called from any route. The app's logout is purely local (packages/happy-app/sources/auth/AuthContext.tsx:40), and Account has no revocable column (schema.prisma:22).

We verified this directly: after both invalidation calls, after a fresh module instance, and with the clock advanced ten years, the token still verifies. There is currently no way for a user to end a leaked session.

Suggested fix: add a monotonic tokenVersion column to Account, carry it in the token, and have verifyToken reject stale versions — bumping the column then ends every outstanding credential. Note that privacy-kit signs {sub, ...extras}, so the version must be nested under extras or verification will reject every token.

2. Any socket on an account can claim another machine's or session's RPC routing key. rpc-register joins rpc:<userId>:<method> using the caller-supplied method string (packages/happy-server/sources/app/api/socket/rpcHandler.ts:66). socket.data.clientType, .machineId and .sessionId are set at handshake (socket.ts:88) and never consulted, so a browser tab or a second device logged into the same account can pre-register <machineId>:bash and receive the requests intended for the real daemon. The handler logs "multiple sockets in room; using first" rather than rejecting (rpcHandler.ts:193), and rpc-unregister gives the legitimate owner no way to evict a squatter (:152).

Params are E2E-encrypted, so a bearer-token-only attacker gets denial of service and ciphertext capture rather than plaintext — but any full account client holds the keys, and the routing decision itself should not be a client-side convention.

Suggested fix: derive the allowed method prefix from socket.data in rpc-register — a machine-scoped socket may register only ${socket.data.machineId}:*, a session-scoped socket only ${socket.data.sessionId}:* — and reject a register that collides with an occupied room instead of silently sharing it.

Adjacent: #1089 proposes rate limiting, which this area also lacks.