Bots creating fake accounts in your app: how to stop them
Turn on CAPTCHA in Supabase Auth with Turnstile or hCaptcha, and lower the signup and email rate limits. Give free credits only after the user confirms the email. Then delete the fake accounts. These steps are free and take about an hour.
This guide shows the signs of bot signups, the exact setup steps, and how to clean up.
How do I know that bots are signing up?
Bot signups follow a pattern. You see the effects first, in the quota or the bill.
These are the common signs:
- Email quota hit. Resend or your SMTP provider says that you reached the limit. Real users then do not get their confirmation mail.
- High bounce rate. The bots use fake addresses. Many confirmation emails bounce. Bounces can harm your sender reputation.
- A burst of new users. The
auth.userstable gains 100 or more rows in a few minutes. - Odd email patterns. Many addresses use the same domain, random strings, or small changes of one name.
- Credit drain. Your AI or API credits go down, with no matching real customer.
- Rate limit errors. Real users see
429errors on the signup form.
The Castle blog describes how bots and fraudsters use free tiers in AI SaaS. Free credits give the attacker a reason to create many accounts. A free AI call has a real cost for you.
Run this query in the Supabase SQL editor. It shows the signups per hour:
select date_trunc('hour', created_at) as hour,
count(*) as signups
from auth.users
where created_at > now() - interval '3 days'
group by 1
order by 1 desc;
Run this one to see the top email domains from the last day:
select split_part(email, '@', 2) as domain,
count(*) as users,
count(*) filter (where email_confirmed_at is null) as unconfirmed
from auth.users
where created_at > now() - interval '1 day'
group by 1
order by users desc
limit 20;
A domain with many users and no confirmations is a strong sign of bots.
Why do bots find my signup form?
A signup form is a public endpoint. The Supabase project URL and the anon key are in your frontend code. This is normal and by design. A bot does not need your form. It can send a request to the Supabase Auth API directly.
A CAPTCHA on your page is not enough if the server does not check it. This is why the setting must be in Supabase, not only in your React code. When you turn it on in Supabase, the Auth server rejects each request without a valid token.
How do I turn on CAPTCHA in Supabase Auth?
Supabase supports hCaptcha and Cloudflare Turnstile. Follow the Supabase CAPTCHA guide. The steps are below.
Step 1: Get the keys
For Turnstile:
- Open the Cloudflare dashboard.
- Create a Turnstile widget.
- Add your site domain to the widget.
- Copy the site key and the secret key.
For hCaptcha:
- Sign up at hcaptcha.com.
- Copy the site key and the secret key.
The site key is public. It goes in your frontend. The secret key is private. Do not put the secret key in your frontend code or in a public repo.
Step 2: Turn it on in Supabase
- Open the Supabase dashboard and select your project.
- Go to Authentication, then to Settings.
- Find the section named Bot and Abuse Protection.
- Turn on Enable CAPTCHA protection.
- Select the provider.
- Enter the secret key.
- Click Save.
Step 3: Add the widget to your frontend
Install the widget package. For React with Turnstile, Supabase suggests @marsidev/react-turnstile. For hCaptcha, it suggests @hcaptcha/react-hcaptcha.
A Turnstile example:
import { useState } from "react";
import { Turnstile } from "@marsidev/react-turnstile";
import { supabase } from "@/lib/supabase";
export function SignupForm() {
const [captchaToken, setCaptchaToken] = useState<string>();
async function onSubmit(email: string, password: string) {
const { error } = await supabase.auth.signUp({
email,
password,
options: { captchaToken },
});
if (error) console.error(error.message);
}
return (
<form onSubmit={(e) => { e.preventDefault(); /* read fields, call onSubmit */ }}>
{/* email and password fields */}
<Turnstile
siteKey={process.env.NEXT_PUBLIC_TURNSTILE_SITE_KEY!}
onSuccess={setCaptchaToken}
/>
<button type="submit" disabled={!captchaToken}>Sign up</button>
</form>
);
}
The captchaToken option goes in the options object. Use the same option in the other auth calls: signInWithPassword, signInWithOtp, and resetPasswordForEmail. Each of them sends mail or checks a password, so bots abuse them too.
A token works for one request. Reset the widget after each try. The hCaptcha component has a resetCaptcha() method for this.
Step 4: Test it
-
Open the form in a private window. Sign up with a real address. The signup must work.
-
Send a request with no token:
curl -i -X POST "https://<project-ref>.supabase.co/auth/v1/signup" \ -H "apikey: <anon-key>" \ -H "Content-Type: application/json" \ -d '{"email":"bot-test@example.com","password":"Test-pass-12345"}' -
The response must be an error status. A 200 response means the CAPTCHA is not active.
-
Test the login, the password reset, and the magic link forms. A form that omits the token now fails. Fix each form.
Caution: Turn on the CAPTCHA only after the frontend sends the token. If you turn it on first, all signups fail until you deploy the code. Mobile apps and other clients also need a token flow.
For local tests, add localhost to the allowed domains of the widget. The Cloudflare and hCaptcha docs explain how.
How do I set signup and OTP rate limits?
CAPTCHA is one layer. Rate limits are the second layer. Supabase sets defaults. The Supabase rate limits page lists them. Some default values are:
- Sign-ups and sign-ins: 30 requests per 5 minutes per IP address.
- OTP and magic link: one request per 60 seconds per user.
- Anonymous sign-ins: 30 per hour per IP address.
- Emails sent with the built-in provider: 2 per hour for the project.
Change them in the dashboard under Authentication, then Rate Limits. You can only change the email limit when you use custom SMTP.
Follow these steps.
- Use your own SMTP provider, such as Resend. The built-in provider is for tests only.
- Lower the limit for sign-ups and sign-ins per IP address. Pick a value that real users do not reach.
- Keep the OTP and confirmation limit at one per 60 seconds, or higher.
- Set a monthly cap with your email provider. A cap limits the damage when an attack passes your checks.
- Turn on usage alerts at 50 and 80 percent of your quota.
Warning: Do not set the limits too low for a shared IP. An office or a school can have many real users on one IP address.
Supabase counts limits by IP address. If your server calls Auth for your users, all calls look like one IP. The rate limits page explains the Sb-Forwarded-For header for this case. Read it before you add a server proxy.
Also add limits to your own API. The guide on Supabase rate limits shows how.
How do I delay free credits until the email is confirmed?
Bots want the free credits. Remove the reward, and the attack loses value.
First, turn on email confirmation. A user then cannot sign in until they click the link. The guide on signup without email confirmation has the steps.
Second, give credits only after confirmation. Use a database trigger or a check in your API. This example checks the confirmation time before it grants credits:
create or replace function public.grant_credits_on_confirm()
returns trigger
language plpgsql
security definer
set search_path = ''
as $$
begin
if old.email_confirmed_at is null and new.email_confirmed_at is not null then
insert into public.credits (user_id, balance)
values (new.id, 20)
on conflict (user_id) do nothing;
end if;
return new;
end;
$$;
create trigger on_email_confirmed
after update of email_confirmed_at on auth.users
for each row execute function public.grant_credits_on_confirm();
Check that the public.credits table exists, and that user_id is its primary key. Test the trigger on a staging project first.
Add more checks in your API for each AI call:
- Require a confirmed email.
- Set a daily cap per user.
- Set a global daily cap for all free users.
- Return
429when a cap is full.
The guide on free ChatGPT abuse explains how to control the cost of free users. The guide on internal-only apps shows how to close signups if your app is not public.
How do I clean up the fake users?
Save a copy first. Then delete.
-
Export the suspect rows to a file. Use the SQL editor and the CSV export.
select id, email, created_at, last_sign_in_at from auth.users where email_confirmed_at is null and created_at > now() - interval '3 days' order by created_at desc; -
Check the list. Make sure that real users are not in it.
-
Check which tables hold data for these users. Look at profiles, credits, and usage tables.
-
Delete the users with the Auth admin API. Do not run
deleteonauth.usersby hand. The admin API handles the related rows. Use the service role key on a server only.import { createClient } from "@supabase/supabase-js"; const admin = createClient( process.env.SUPABASE_URL!, process.env.SUPABASE_SERVICE_ROLE_KEY! ); for (const id of idsToDelete) { const { error } = await admin.auth.admin.deleteUser(id); if (error) console.error(id, error.message); } -
Run the first SQL query again. Check that the count dropped.
-
Ask your email provider to clear the bounces, if your sender reputation fell.
Warning: Do not run the delete script from the browser. The service role key bypasses all access rules. Keep it on the server. If the key leaked, rotate it first.
Delete in small batches. Check a few results after the first batch.
How do I stop this in the future?
Use layers. One check is not enough.
- Keep CAPTCHA on for all auth forms.
- Use email confirmation.
- Keep rate limits low and use custom SMTP.
- Grant credits after confirmation, and cap them per user and per day.
- Set an alert for signup spikes. Run the hourly query on a schedule, or use your provider alerts.
- Block known disposable email domains if your users do not need them.
- Check the signup flow after each release. AI tools can change auth code, and can remove the token without notice.
Review the app once a month. Look at the unconfirmed users, the bounce rate, and the cost per user.
When should I get help?
Ask for help in these cases:
- The attack continues after CAPTCHA, limits, and email confirmation.
- The bill grows and you cannot find the source.
- You see real users in the fake list, and you cannot split them.
- The service role key may be public.
- Your email domain landed on a block list.
Contact your email provider first. They can pause sending and review the traffic. Then run a scan of your live app, to find the auth endpoints that still accept requests without a check.
Common questions
Does CAPTCHA stop all bot signups?
Is Turnstile or hCaptcha better for Supabase?
Why did my CAPTCHA not stop the attack?
Must I delete the fake users?
Can I turn on the CAPTCHA with no code change?
Test your signup flow
A VibeEval scan tests the live app and API from outside. It checks the signup and auth endpoints for open access, weak limits, and missing email confirmation.
14-day free trial · Cancel anytime