Skip to content

fix(api): rate-limit authenticated routes by user id - #119

Merged
shreechaturvedi merged 1 commit into
mainfrom
fix/89-rate-limit-by-user-id
Aug 3, 2026
Merged

shreechaturvedi merged 1 commit into
mainfrom
fix/89-rate-limit-by-user-id

Conversation

@shreechaturvedi

Copy link
Copy Markdown
Owner

Summary

  • Run rate limiting after authenticateJWT in createApiHandler and createMethodHandler when requireAuth is set.
  • Authenticated traffic is bucketed by req.user.id (default keyGenerator), so shared-NAT users no longer share one IP budget.
  • Public/auth routes stay IP-keyed (no JWT runs first).
  • Add lib/utils/__tests__/apiHandler.test.ts covering order, per-user budgets, and public IP keying.

Closes #89.

Test plan

  • npm run test:backend:run (642 passed incl. 6 new)
  • typecheck api + app
  • full build
  • CI green on PR

Move rate limiting after authenticateJWT in createApiHandler and
createMethodHandler so the default keyGenerator can bucket on
req.user.id. Shared-NAT users no longer share one IP budget on
requireAuth routes; public/auth tiers stay IP-keyed. Closes #89.
@shreechaturvedi
shreechaturvedi merged commit 3be077c into main Aug 3, 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.

Rate limit: key authenticated routes by user id

1 participant