Repository navigation
feat(auth): rate limit anonymous session initialization (#312) - #475
Open
ankit-0903 wants to merge 2 commits into
Open
ankit-0903 wants to merge 2 commits into
ankit-0903 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want higher recall? High effort reviews run extra passes and find more bugs. A team admin can switch effort levels in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit fe81c8f. Configure here.
This branch has not been deployed
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.

Resolves #312
Summary
Adds IP-based rate limiting to anonymous session initialization (
_system.session.init) and guest user creation, protecting against anonymous session table flooding and token enumeration attacks:sessionInitrate limits:100requests per 15 minutes and1,000requests per day per IP.auth.rateLimits.sessionInittoAuthRateLimitsConfigfor per-app configuration overrides._system.session.init, requests consume thesessionInitrate limit whenconnectionInfo.ipis present and the session has no authenticated user (!contextSession || !contextSession.userId).TODO: add rate-limiting and captcha handlingcomment oncreateSession.createGuestUserconsumessignupAttemptandsignuprate limits when IP is provided.11000) before throwing, addressingTODO: re-try on handle collision.Verification
npm run test -- src/auth/session.test.ts src/auth/user.test.ts(66 tests passed)npm run test -- src/auth/(34 test files / 639 tests passed)npm run lint:check(0 errors, 0 warnings)npm run build(ESM & DTS builds passed)Note
Medium Risk
Changes authentication session init and guest signup paths with IP-based throttling; misconfiguration or aggressive defaults could block anonymous traffic, but setup and authenticated flows are explicitly exempt.
Overview
Adds per-IP rate limiting for anonymous session initialization and tightens guest account creation.
A new configurable
sessionInitbucket (defaults: 100 per 15 minutes and 1,000 per day per IP) is wired into_system.session.initviaconsumeRateLimit. Limits apply only when the caller has an IP, an existing anonymous session, and setup mode is not active (sessionnull); logged-in users and requests without IP are unchanged.createGuestUseroptionally acceptsconnectionInfoand, when an IP is present, consumes existingsignupAttemptandsignuplimits. Guest handle creation now retries up to five times on Mongo duplicate-key (11000) before failing. Stale rate-limit TODOs on session/guest paths are removed. Tests cover init throttling edge cases, default/overridesessionInitrules, guest rate limits, and collision retries.Reviewed by Cursor Bugbot for commit e8dd611. Bugbot is set up for automated code reviews on this repo. Configure here.