fix(auth): disable API key rate limiting — breaks MCP after ~7 calls#2902
Conversation
Better-auth defaults to 10 requests per 24 hours per API key. MCP clients burn 3 requests on init alone, causing keys to stop working after ~7 tool calls. Disables the rate limiter entirely.
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/auth/src/server.ts`:
- Around line 175-177: The apiKey plugin's rateLimit is being unconditionally
disabled (rateLimit.enabled = false) in the auth server; restore
application-layer protection by either re-enabling rate limiting with sensible
defaults (e.g., timeWindow and maxRequests matching the DB defaults used in
packages/db/src/schema/auth.ts) or gate the disable behind an explicit
environment variable (e.g., check process.env.ENABLE_API_KEY_RATE_LIMIT and set
rateLimit.enabled accordingly). Update the rateLimit block in the apiKey plugin
configuration in packages/auth/src/server.ts to read the env flag (or set
enabled: true and configure timeWindow/maxRequests) so per-key limits are
enforced or opt-in disabled explicitly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3295bb8d-887c-4487-9ea6-654cdb652954
📒 Files selected for processing (1)
packages/auth/src/server.ts
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
Summary
Context
Customer reported API keys dying after a handful of MCP tool calls. Root cause is better-auth's aggressive default rate limit config that we weren't overriding.
Test plan
Summary by cubic
Disabled
better-authAPI key rate limiting to stop MCP keys from being blocked after ~7 calls. Our infra already enforces rate limits, so keys now work beyond the previous 10-requests/24h default.rateLimit.enabled = falsein the API key plugin.Written for commit f248042. Summary will update on new commits.
Summary by CodeRabbit