Email rate limits #733

Closed
opened 2026-03-13 08:02:01 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @daveycodez on GitHub (Feb 24, 2025).

Is this suited for github?

  • Yes, this is suited for github

Describe the solution you'd like

As of right now it seems like the only rate limits in place are for HTTP endpoints and defaults to using RAM to track these rate limits. This is fine for preventing database abuse, but email abuse is another issue.

I believe it would be ideal to by default use the database for rate limiting any outgoing emails and have safe defaults set. Someone should not be able to rotate IP addresses and request emails to be sent. It should be rate limited based on the email address itself, not the IP or other user identifiers.

Describe alternatives you've considered

Custom check to see when the last email was sent to a given email in each sendEmail callback

Originally created by @daveycodez on GitHub (Feb 24, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### Describe the solution you'd like As of right now it seems like the only rate limits in place are for HTTP endpoints and defaults to using RAM to track these rate limits. This is fine for preventing database abuse, but email abuse is another issue. I believe it would be ideal to by default use the database for rate limiting any outgoing emails and have safe defaults set. Someone should not be able to rotate IP addresses and request emails to be sent. It should be rate limited based on the email address itself, not the IP or other user identifiers. ### Describe alternatives you've considered Custom check to see when the last email was sent to a given email in each sendEmail callback
Author
Owner

@hansaskov commented on GitHub (Feb 24, 2025):

Something to consider with your suggestions is that rate limiting based on email instead of ip could be used maliciously to target a specific user and cause a denial of service.

@hansaskov commented on GitHub (Feb 24, 2025): Something to consider with your suggestions is that rate limiting based on email instead of ip could be used maliciously to target a specific user and cause a denial of service.
Author
Owner

@daveycodez commented on GitHub (Feb 24, 2025):

This is a fair point. But I think we need some solid best practice defaults here without relying on RAM, since a lot of people are using serverless environments. I'm not sure what Clerk is doing but it's worth looking into. Email abuse can lead to blacklisting auth emails.

I think the email rate limits should be a totally separate check from the other rate limits. I think for now I will test Vercel firewall for any endpoints that trigger emails. Only issue is that will lock a user out for the rest of the window if they surpass it.

It would be great to get a list of all endpoints that send emails and maybe even include a regex example of how to match all of the email endpoints via middleware

@daveycodez commented on GitHub (Feb 24, 2025): This is a fair point. But I think we need some solid best practice defaults here without relying on RAM, since a lot of people are using serverless environments. I'm not sure what Clerk is doing but it's worth looking into. Email abuse can lead to blacklisting auth emails. I think the email rate limits should be a totally separate check from the other rate limits. I think for now I will test Vercel firewall for any endpoints that trigger emails. Only issue is that will lock a user out for the rest of the window if they surpass it. It would be great to get a list of all endpoints that send emails and maybe even include a regex example of how to match all of the email endpoints via middleware
Author
Owner

@theinfinit commented on GitHub (Feb 24, 2025):

@Bekacru as of now, in 1.2.0-beta.16, it seems like rate-limiting is not applied at all for /api/auth/send-verification-email.

In comparison, endpoints like /api/auth/two-factor/verify-totp are rate-limited as expected.

Only after adding custom rule, verification email endpoint starts to be rate-limited (then the question would be, which endpoints are rate-limited, and which are not).

rateLimit: { 
	enabled: true,
	customRules: {
		"/send-verification-email": {
				window: 10,
				max: 3,
		},
	}
},

This is especially important, as this endpoint is available for everyone on client-side for use and abuse.

@theinfinit commented on GitHub (Feb 24, 2025): @Bekacru as of now, in `1.2.0-beta.16`, it seems like rate-limiting is not applied at all for `/api/auth/send-verification-email`. In comparison, endpoints like `/api/auth/two-factor/verify-totp` are rate-limited as expected. Only after adding custom rule, verification email endpoint starts to be rate-limited (then the question would be, which endpoints are rate-limited, and which are not). ```js rateLimit: { enabled: true, customRules: { "/send-verification-email": { window: 10, max: 3, }, } }, ``` This is especially important, as this endpoint is available for everyone on client-side for use and abuse.
Author
Owner

@dosubot[bot] commented on GitHub (Jun 15, 2025):

Hi, @daveycodez. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Proposal to implement database-based rate limiting for outgoing emails to prevent abuse.
  • Concern raised about potential exploitation for denial of service targeting specific users.
  • Emphasis on best practice defaults that don't rely on RAM, especially for serverless environments.
  • Noted inconsistency in rate limiting rules across endpoints, particularly in version 1.2.0-beta.16.

Next Steps:

  • Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here.
  • If no updates are provided, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

@dosubot[bot] commented on GitHub (Jun 15, 2025): Hi, @daveycodez. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Proposal to implement database-based rate limiting for outgoing emails to prevent abuse. - Concern raised about potential exploitation for denial of service targeting specific users. - Emphasis on best practice defaults that don't rely on RAM, especially for serverless environments. - Noted inconsistency in rate limiting rules across endpoints, particularly in version `1.2.0-beta.16`. **Next Steps:** - Please confirm if this issue is still relevant to the latest version of the better-auth repository by commenting here. - If no updates are provided, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#733