Skip to content

fix(auth): rate limit profile updates - #313

Merged
omegascorp merged 1 commit into
modelence:mainfrom
aadityakumarsah:fix/auth-rate-limiting
Aug 27, 2026
Merged

fix(auth): rate limit profile updates#313
omegascorp merged 1 commit into
modelence:mainfrom
aadityakumarsah:fix/auth-rate-limiting

Conversation

@aadityakumarsah

@aadityakumarsah aadityakumarsah commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add per-user limits for profile updates (30 per 15 minutes; 200 per day)
  • expose auth.rateLimits.updateProfile for configuration overrides
  • validate profile updates and handle availability before consuming the quota
  • add coverage for defaults, overrides, validation failures, and successful updates

This branch was rebuilt from current main and contains only the profile-update rate-limit change.

Testing

  • npm run lint:check
  • npm run build
  • npm test

Note

Low Risk
Scoped to profile update mutation with conservative defaults; quota is not consumed on validation failures, limiting user impact.

Overview
Adds per-user rate limiting on profile updates so abusive or automated updateProfile traffic is capped like other auth actions.

Default limits are 30 updates per 15 minutes and 200 per day per user, registered on the auth module’s rate-limit rules. Apps can tune them via auth.rateLimits.updateProfile using the same override/merge behavior as other auth buckets.

handleUpdateProfile now calls consumeRateLimit with bucket updateProfile only when there is a non-empty update to persist—after field validation, the optional validateProfileUpdate hook, and handle uniqueness checks—so invalid or rejected requests do not burn quota. Tests cover defaults, overrides, and when the limit is (not) consumed.

Reviewed by Cursor Bugbot for commit 1af3bfb. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread packages/modelence/src/auth/profile.ts Outdated
}

export async function handleUpdateProfile(props: Args, { user }: Context) {
export async function handleUpdateProfile(props: Args, { user, connectionInfo }: Context) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused connectionInfo

Comment thread packages/modelence/src/auth/session.ts Outdated
});
}

import { consumeRateLimit } from '../rate-limit/rules';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move the import statement to the top, follow clean code

Comment thread packages/modelence/src/auth/user.ts Outdated

export async function createGuestUser() {
// TODO: add rate-limiting and captcha handling
import { Context } from '../methods/types';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move import statement to the top

Comment thread packages/modelence/src/auth/login.ts Outdated
Comment thread packages/modelence/src/auth/user.ts Outdated
Comment thread packages/modelence/src/auth/login.ts Outdated
Comment thread packages/modelence/src/websocket/socketio/client.ts Outdated
Comment thread packages/modelence/src/auth/user.ts Outdated
Comment thread packages/modelence/src/auth/session.ts Outdated
Comment thread packages/modelence/src/auth/user.ts Outdated
@aadityakumarsah
aadityakumarsah force-pushed the fix/auth-rate-limiting branch from 9dcb7c3 to bce2c56 Compare July 19, 2026 12:41
@omegascorp

omegascorp commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

@aadityakumarsah why do we need a rate limit on sessionInit? This basically means that when a lot of users visit from the same IP, it will start blocking them. Example of a false positive failure: a large company is using a product built on Modelence, and hundreds of users are visiting from the same corporate IP

@aadityakumarsah
aadityakumarsah force-pushed the fix/auth-rate-limiting branch from bce2c56 to 65d551d Compare July 22, 2026 12:58
@aadityakumarsah aadityakumarsah changed the title fix(auth): add rate limiting to session init and profile updates fix(auth): rate limit profile updates and refresh bfcache sessions Jul 22, 2026
@aadityakumarsah

Copy link
Copy Markdown
Contributor Author

@omegascorp You are right. sessionInit is the wrong place for an IP-based rate limit: clients behind corporate/carrier NATs could be blocked, and the session is already created before the handler runs, so it does not reliably cap session creation. I removed the sessionInit limiter and its configuration while resolving the branch conflicts. The remaining profile-update limit is keyed by authenticated user ID, not IP.

Comment thread packages/modelence/src/auth/signup.ts
Comment thread packages/modelence/src/auth/profile.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e1d197e. Configure here.

Comment thread packages/modelence/src/client/renderApp.tsx Outdated
@omegascorp

Copy link
Copy Markdown
Collaborator

@aadityakumarsah this branch seems to have the same issue as the other branches - it has unrelated changes

@aadityakumarsah
aadityakumarsah force-pushed the fix/auth-rate-limiting branch from c6c2fa6 to 1af3bfb Compare July 22, 2026 13:53
@aadityakumarsah aadityakumarsah changed the title fix(auth): rate limit profile updates and refresh bfcache sessions fix(auth): rate limit profile updates Jul 22, 2026
@omegascorp
omegascorp self-requested a review August 27, 2026 12:07
@omegascorp
omegascorp merged commit d16e98d into modelence:main Aug 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants