🔧 Unbreak My AppAll fixesError codesFix KitsSponsor

Fixes › Auth

Login rate limit only counts per email: credential stuffing gets through

LovableBoltCursorReplitv0

Published

Weakness type: CWE-307 (Improper Restriction of Excessive Authentication Attempts)

The error

Users report their account was taken over even though my login has a rate limit / Auth logs show many failed sign-ins, each for a different email, often one or two tries each / a security scan says login rate limiting is keyed only on username or email (credential stuffing, password spraying) / my per-email lockout locks real users out / every user suddenly gets 429 over_request_rate_limit because my server calls signInWithPassword for everyone

Why it happens

AI builders usually add a login limit like 'block an email after 5 failed tries'. That stops one kind of attack, guessing many passwords for one account (brute force). It does not stop credential stuffing, where an attacker takes email and password pairs leaked from other sites and tries each pair once on your app, or password spraying, where one common password is tried against many accounts. OWASP's Credential Stuffing Prevention Cheat Sheet describes both and says toolkits spread requests over large proxy networks so the volume per IP address stays low, which can defeat IP block lists and rate limiting. So a per-email counter never reaches its threshold, and a per-IP counter alone can be dodged too. Two vibe-coding details make it worse. First, if the browser calls supabase.auth.signInWithPassword with your public key, your own limiter in an API route is never in the path: anyone can call the Supabase Auth endpoint directly, and only Supabase's own per-IP limits apply (by default 150 requests per 5 minutes per IP for the /auth/v1/token endpoint that password sign-in uses, with bursts up to 30). Second, if your server calls Supabase for every user, Supabase sees your server's IP, so all users share one limit and real people get 429 over_request_rate_limit unless you forward the user's IP. A hard lockout per email has its own problem: OWASP warns it can be used to lock other users out on purpose.

How to fix it

  1. Find out how your login works. Search the code for signInWithPassword. If it runs in the browser, your own rate limit code (if any) is not protecting the Supabase Auth endpoint, because anyone can call it directly with your public key. If it runs on your server (an API route, Server Action or Edge Function), note that Supabase sees your server's IP address, not the user's.
  2. Check the signs of an attack. In the Supabase dashboard open Logs and the Auth logs and look for many failed password sign-ins (invalid_credentials) across many different emails, or bursts from many IP addresses. Supabase Auth audit logs record sign-ins, password changes and resets; you can also write them to the auth.audit_log_entries table to search them with SQL.
  3. Review Supabase's own limits instead of building your own first. Go to Authentication > Rate Limits. Supabase uses a token bucket per IP address: the token endpoint (password, refresh token and PKCE sign-ins) defaults to 150 requests per 5 minutes with bursts up to 30, and sign-ups, magic links and password resets default to 30 per 5 minutes. Over the limit, Supabase answers 429 with over_request_rate_limit. Lower the values if your real traffic allows it. These are per IP, so treat them as one layer, not the whole defence.
  4. If your server signs users in, forward the real user IP. Otherwise every user shares your server's limit, and an attacker hitting your server can lock everyone out. Turn on IP Address Forwarding under Authentication > Rate Limits, then on the server send the Sb-Forwarded-For header with the end user's IP. Supabase only accepts this header together with a secret API key (sb_secret_...), not the publishable or legacy anon key, so keep that key on the server only.
  5. Turn on CAPTCHA for sign-in, sign-up and password reset. In Authentication > Bot and Abuse Protection, enable CAPTCHA protection and choose hCaptcha or Cloudflare Turnstile with its secret key. Then add the widget to your forms and pass its token: supabase.auth.signInWithPassword({ email, password, options: { captchaToken } }), and the same option on signUp and resetPasswordForEmail. If you forget the token, sign-in fails with captcha_failed. Reset the widget after each try. OWASP calls CAPTCHA defence in depth, not a complete fix, because some CAPTCHAs can be solved by services.
  6. Offer MFA, and require it for admins. OWASP calls multi-factor authentication by far the best defence against credential stuffing and password spraying. Supabase's TOTP (authenticator app) MFA API is free and enabled on all projects by default. Let users enrol, check the aal2 level in your app and in RLS policies for sensitive actions, and make it mandatory for every admin account.
  7. Stop leaked passwords at sign-up and password change. In Supabase Auth password settings set a minimum length (Supabase says less than 8 is not recommended) and, on the Pro plan and above, turn on leaked password protection, which checks passwords against HaveIBeenPwned's Pwned Passwords. On the Free plan you can call the Pwned Passwords range API yourself from your server before sign-up: HIBP says it is free and needs no API key, and you only send the first 5 characters of the password's SHA-1 hash.
  8. If you keep your own limiter, count more than one thing and do not hard-lock accounts. Count failures per account and per IP, watch the total failure rate across all accounts (one attempt each on hundreds of emails is the stuffing pattern), and respond by asking for a CAPTCHA or adding a growing delay rather than locking the account for good. OWASP warns that lockouts can be abused to lock out other users and suggests still letting a locked user recover through the forgot password flow. Show the same generic message (for example 'Email or password is incorrect') whether the email exists or not.
  9. Verify. In a private window, try a wrong password several times: you should see the generic error and then the CAPTCHA or a delay, never a message that says the email does not exist. Remove the captchaToken in a test build and confirm sign-in fails with captcha_failed. If your server signs users in, confirm two different users on different networks are rate limited separately. Then sign in as an admin and confirm MFA is required.

Fix prompt (paste into Lovable, Bolt, Cursor, Replit or v0)

My app's login only rate limits failed attempts per email, which does not stop credential stuffing (one leaked password per account from many IPs). Do not disable Row Level Security, do not put any secret or service role key in the browser, and do not add a permanent account lockout. 1) Show me where signInWithPassword, signUp and resetPasswordForEmail are called and whether each runs in the browser or on the server. 2) Add Cloudflare Turnstile (or hCaptcha) to the sign-in, sign-up and password reset forms and pass the token as options.captchaToken on each call; tell me what to enable under Authentication > Bot and Abuse Protection. 3) If sign-in runs on my server, forward the user's IP with the Sb-Forwarded-For header using a server-only secret key, and tell me to enable IP Address Forwarding in Authentication > Rate Limits. 4) Make every login error show the same generic message whether or not the email exists. 5) Add optional TOTP MFA for users and require it (aal2) for admin accounts. 6) Before sign-up and password change, check the password against the Pwned Passwords range API from the server and reject leaked ones. 7) Tell me how to test each change.

Error codes this fixes

FAQ

Why doesn't a per-email login limit stop credential stuffing?

Because credential stuffing tries each leaked email and password pair once, often from many IP addresses. Each account sees only one or two failures, so a counter per email never reaches its limit. OWASP recommends layers: MFA first, then CAPTCHA, IP checks and leaked password blocking.

Does Supabase rate limit password sign-ins?

Yes, per IP address. The /auth/v1/token endpoint used for password sign-in defaults to 150 requests per 5 minutes with bursts up to 30, and you can change it under Authentication > Rate Limits. Over the limit Supabase returns 429 over_request_rate_limit. It is per IP, so it does not stop an attack spread over many IPs.

Why do all my users get over_request_rate_limit at once?

Your server is probably calling Supabase Auth for everyone, so Supabase sees one IP address. Enable IP Address Forwarding in Authentication > Rate Limits and send the user's IP in the Sb-Forwarded-For header, which Supabase only accepts with a secret key used on the server.

Should I lock accounts after 5 failed logins?

Not permanently. OWASP warns that lockouts can be used to lock out real users on purpose. Prefer a CAPTCHA or a growing delay after a few failures, keep the forgot password flow working, and use MFA for real protection.

Is leaked password protection free on Supabase?

Supabase's built-in leaked password protection, which uses HaveIBeenPwned's Pwned Passwords, is on the Pro plan and above. The Pwned Passwords range API itself is free with no API key, so on the Free plan you can check new passwords from your own server.

Sources

Based on the official documentation:

Related fixes

Want the full checklist for this area? Get a Fix Kit ($29)

Get one new fix a week

Free newsletter: the newest breakages in Lovable, Bolt, Cursor, Replit and v0 apps, with paste-in fixes.

We only use your email to send the newsletter. Unsubscribe any time. See privacy.