AleannLab

No Rate Limiting: What Happens to Login, Signup and Email Endpoints

AleannLab team3 min read

Any endpoint a script can call a thousand times a minute will be, sooner or later. Without rate limits, attackers test stolen passwords against your login, create fake accounts in bulk, and make your app send email or SMS at your expense. Put limits on login, signup, password reset, anything that sends a message, and anything that costs money per call. Key them by IP address and by account, in a shared store.

On this page
  1. What goes wrong
  2. What to limit, and by what
  3. Add it in code
  4. Use what your platform already has
  5. Do not turn limits into a new problem
  6. Test it

AI-generated apps almost never include rate limiting, because nothing breaks without it during development. It only matters once strangers arrive.

What goes wrong

Credential stuffing. Attackers replay email and password pairs leaked from other sites. They are not guessing: a small share of your users reuse passwords, and those accounts open.

Brute force on short codes. A six-digit email or SMS code has a million combinations. Without attempt limits, a script walks through them.

Email and SMS abuse. "Send reset link" and "resend verification" let anyone make your domain send mail to any address. That burns your sender reputation and your provider quota. SMS is worse: fraudsters trigger messages to premium-rate numbers they profit from, and you get the bill.

Fake signups. Thousands of accounts to abuse free tiers, trial credits or referral bonuses.

Scraping and enumeration. Walking through IDs or search results to copy your data, or probing which emails have accounts.

Cost. Endpoints that call an LLM or another paid API. We covered that case in no cap on LLM API spend.

What to limit, and by what

EndpointKeyA reasonable start
LoginIP, and email10 per 10 min per IP; 5 failures per 15 min per email
SignupIP5 per hour
Password reset, resend verificationIP, and target email3 per hour per email
Code verification (OTP)Account5 attempts per code, then issue a new one
Send SMSAccount, phone number, IP3 per hour per number, plus a daily cap overall
Expensive or write endpointsUserBased on real usage

Use two keys for auth endpoints. A limit per IP alone is defeated by a botnet. A limit per account alone lets an attacker spread guesses across many accounts from one machine.

Add it in code

Counters must live in a shared store. An in-memory Map resets on every deploy and is separate for each serverless instance.

TypeScript
import { Ratelimit } from '@upstash/ratelimit';
import { Redis } from '@upstash/redis';

const redis = Redis.fromEnv();
const byIp = new Ratelimit({ redis, limiter: Ratelimit.slidingWindow(10, '10 m'), prefix: 'login:ip' });
const byEmail = new Ratelimit({ redis, limiter: Ratelimit.slidingWindow(5, '15 m'), prefix: 'login:email' });

export async function POST(req: Request) {
  const { email, password } = Body.parse(await req.json());
  const ip = req.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ?? 'unknown';

  const [a, b] = await Promise.all([byIp.limit(ip), byEmail.limit(email.toLowerCase())]);
  if (!a.success || !b.success) {
    return Response.json({ error: 'Too many attempts. Try again later.' },
      { status: 429, headers: { 'Retry-After': '600' } });
  }
  // ...check the password
}

About the IP address: x-forwarded-for can be set by the client. Trust it only when your platform overwrites it (Vercel and Cloudflare do), and read the value your host documents.

Use what your platform already has

  • Supabase Auth, Clerk, Auth0, Firebase Auth have built-in limits for sign-in and email sending. Check the settings instead of assuming. Your own endpoints around them are still unprotected.
  • Cloudflare, Vercel Firewall and similar can rate limit by path before requests reach your code.
  • CAPTCHA or Turnstile on signup and reset forms stops the simple scripts. It complements limits and does not replace them.

Do not turn limits into a new problem

  • Lockouts as a weapon. If five failures lock an account for a day, anyone can lock out your users. Prefer short delays that grow, and never lock on the email key alone for long.
  • Same answer either way. "If an account exists, we sent a link" for every reset request. Different responses let attackers build a list of your users. More in weak password reset.
  • Tell real users what happened. A 429 with a clear message and Retry-After, not a silent failure.

Test it

bash
for i in $(seq 1 20); do
  curl -s -o /dev/null -w "%{http_code} " -X POST https://yourapp.com/api/auth/login \
    -H 'Content-Type: application/json' -d '{"email":"test@example.com","password":"wrong"}'
done

You should see 401 turn into 429 partway through. Repeat for reset and resend endpoints, and check your email provider's log to confirm the sends stopped as well.

Rate limits are check 10 in our security checklist for vibe-coded apps. If you would like limits, bot protection and alerting set up across your app, that is part of our app rescue and security audit.

All articles →

Gotowy, aby omówić swój projekt z nami?

idea
*
*
*
Interesuje mnie...
Tworzenie stron internetowych
Tworzenie aplikacji
Projektowanie UX/UI
DevOps
Sztuczna inteligencja i uczenie maszynowe
Testowanie QA
Tworzenie aplikacji mobilnych
Konsultacja
Outsourcing
Budżet projektu (USD)
≤ $5K
$10K-$20K
$30K-$40K
$50K-$60K
>$100K
Prześlij plik