Feat/room dos protection 198 - #215
Open
queentiffany1111-cloud wants to merge 2 commits into
Open
Conversation
…refresh (RiftCore00#197) - Validate iss and aud claims against AUTH_ISSUER/AUTH_AUDIENCE env vars - Add clock-skew tolerance (±30s, configurable via AUTH_CLOCK_SKEW_MS) - Add JWKS endpoint support (http+https) with TTL caching and RSA/EC key support - Explicitly reject alg:none tokens before jwt.verify - Pre-validate iss claim to ensure correct error ordering over aud check - Restrict allowed algorithms to HS256, RS256, ES256 - Add token_refresh message handler in server.js; updates client identity on success - Make wss connection callback async to support await verifyConnection - Add auth-hardening.test.js and refresh.test.js test suites - All 173 tests pass, lint clean
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.
Title
resource exhaustion attacks:
- A single misbehaving client could join 100,000 distinct room IDs, accumulating ~10MB+ of pure internal Map/Set overhead.
- A single room could accumulate 50,000+ clients, causing
broadcast()calls to block the V8 event loop for ~50ms per broadcast.breaker, and real-time metrics exposure for
RoomManager."error", payload: { code: "CIRCUIT_BREAKER_OPEN", message: "..." } }
. - **CLOSED State**: Automatically closes when memory drops belowrecoveryThresholdBytes` (default: 384MB or 75% of threshold).total room ceilings are hit.
- Enforced synchronously without yielding execution to avoid TOCTOU (Time-of-Check to Time-of-Use) race conditions.
- Disconnection cleanup and room departure (
leave(),disconnect()) bypass limit checks to guarantee clients can always unsubscribe ordisconnect cleanly.
• totalMembers is tracked in O(1) time on join, leave, and disconnect operations.
──────
Test Coverage
• Added tests/room-manager-dos.test.js covering:
• Limits enforcement (maxRoomsPerClient, maxMembersPerRoom, maxRooms).
• Re-joining an existing room while at maximum capacity limits.
• Circuit breaker state transitions (CLOSED ➔ OPEN ➔ CLOSED).
• Hysteresis behavior between recovery and memory thresholds.
• Metrics tracking (roomCount, clientCount, totalMembers, circuitBreakerState).
• All 23 test suites (187 unit tests) pass cleanly.
• npm run lint passes with zero ESLint errors or warnings.
──────
Verification Commands
closes #198