Repository navigation
feat(api): cap concurrent WebSocket connections per user - #73
Merged
Merged
Conversation
Handshakes beyond WS_MAX_CONNECTIONS_PER_USER get HTTP 429 before the upgrade. Refs #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
- connLimiter counts active /ws streams per verified token subject. - The slot is reserved after token verification and before the upgrade; over the limit the handshake gets 429 TOO_MANY_CONNECTIONS, so a rejected client costs no WebSocket resources. - The slot is released when the stream ends for any reason, including a failed upgrade. - WS_MAX_CONNECTIONS_PER_USER config (default 5, must be >= 1). Refs #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Refs #72 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xzt3HRqVzoHnEyEUbTT3h9
Resolve the threat-model conflict with RBAC (#69): keep the per-user WebSocket cap in the denial-of-service row and the server-side role check in the elevation-of-privilege row. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013Yguxp4QdXefV36UWrij2T
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This bounds how many concurrent
/wsevent streams a single user can hold. Until now, one valid token could open an unbounded number of streams. Each stream holds a goroutine pair, a 64-event buffer and a hub subscription.Closes #72
Architecture summary
contracts/asyncapi.yaml(0.2.0 → 0.3.0) documents that a handshake beyondWS_MAX_CONNECTIONS_PER_USERis rejected with HTTP 429TOO_MANY_CONNECTIONSbefore the upgrade.realtime/httpapi.connLimiter: a mutex-guardedmap[userID]int./wshandler reserves a slot after token verification and beforewebsocket.Accept.defer releasefrees the slot however the stream ends: client close, slow-consumer drop, token expiry, shutdown, or a failed upgrade such as a 403 for a disallowed origin.user_id). A client cannot choose it.WS_MAX_CONNECTIONS_PER_USER, default 5, validated to be at least 1. It is added to.env.exampleanddocker-compose.yml.container-design.md.Security considerations
realtime: connection limit reachedwithuser_idonly. No tokens and no emails are logged.POST /loginrate limiting stay in the threat model's Planned column.Testing evidence
net/httpand WebSocket stack:TOO_MANY_CONNECTIONS.101). Restoring the check makes them pass.WS_MAX_CONNECTIONS_PER_USER=2:user_id.0and of non-integer values.Known limitations
Follow-up issues
POST /login(threat model, Planned).Checklist
main. This PR is stacked on feat: transactional outbox relay and in-process WebSocket hub #65 and will be retargeted tomainonce feat: transactional outbox relay and in-process WebSocket hub #65 merges.make verifypasses locally.git diff --checkis clean.