Learn why static disposable-email blocklists fail against rotating-domain botnets and how to build layered signup protection using Cloudflare Turnstile, DNS-over-HTTPS MX checks, and edge rate limiting.
Self-serve signup flows are a prime target for automated abuse. Modern signup bots no longer hammer an API from a single IP using mailinator.com—they distribute requests across residential proxies and mint hundreds of throwaway subdomains on free DNS providers.
If your signup endpoint only checks a static blocklist or basic IP rate limits, bots will slip through, pollute your CRM, trigger downstream onboarding emails, and burn compute. Here is how to build a defense-in-depth authentication posture at the edge without adding friction for legitimate users.
Checking an email domain against an open-source disposable-email list is a great first line of defense, especially when you walk up parent domains so wildcard subdomains (e.g., [email protected]) are caught by the root entry:
export function matchesDomainList(domain: string, blocklist: ReadonlySet<string>): boolean {
let current = domain.trim().toLowerCase();
while (current) {
if (blocklist.has(current)) return true;
const dot = current.indexOf('.');
if (dot === -1) break;
current = current.slice(dot + 1);
}
return false;
}
Where it breaks: Attackers can register or rotate through dozens of fresh subdomains on free dynamic DNS providers every hour. By the time a domain makes it onto a community blocklist, the botnet has already moved on. Static lists are necessary, but they are always reactive.
To stop automated signups without forcing real users through frustrating puzzles, combine four complementary controls at the edge:
Before touching your database or sending a magic link, require a short-lived challenge token on signup, login, and magic-link endpoints.
A common mistake is checking only success === true on the siteverify response. To prevent token replay across forms or origins, always validate four things server-side:
success === true — the token is valid and unspent.action — bind the token to the specific flow (signup vs. login) so a token minted on one form cannot be replayed on another.hostname — pin allowed origin hostnames so tokens generated on preview/staging environments cannot be submitted to production.remoteip — pass the edge client IP (cf-connecting-ip) for stronger risk scoring.const body = new URLSearchParams({
secret: turnstileSecret,
response: token,
remoteip: clientIp,
});
const res = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body,
});
const data = await res.json();
const valid =
data.success === true &&
data.action === expectedAction &&
allowedHostnames.has(data.hostname?.toLowerCase());
If verification fails, fail closed with 403 before any database write or outbound email is triggered.
Even when attackers rotate sender domains every few minutes, those domains almost always point their DNS MX records at the same small pool of throwaway mail servers.
On edge runtimes like Cloudflare Workers where Node's node:dns module isn't available, you can query DNS-over-HTTPS (DoH) directly over fetch:
export async function resolveMxHosts(domain: string): Promise<string[]> {
const url = `https://cloudflare-dns.com/dns-query?name=${encodeURIComponent(domain)}&type=MX`;
const res = await fetch(url, {
headers: { Accept: 'application/dns-json' },
signal: AbortSignal.timeout(2500),
});
if (!res.ok) return [];
const data = (await res.json()) as { Answer?: Array<{ type?: number; data?: string }> };
return (data.Answer ?? [])
.filter(a => a.type === 15 && typeof a.data === 'string')
.map(a => a.data!.trim().split(/\s+/).pop()!.replace(/\.$/, '').toLowerCase())
.filter(Boolean);
}
Cache the resolved MX hosts in memory for 10 minutes, bound the lookup with a short timeout (e.g., 2.5 seconds), and match the returned mail exchangers against known disposable MX providers. That stops brand-new throwaway domains on their very first signup attempt.
When an abuse wave hits, you shouldn't have to cut a new application release just to block a newly spotted domain. Keep an environment-configurable domain list alongside your built-in blocklist so security and on-call engineers can push emergency blocks via configuration in minutes.
POST /auth/magic-link trigger third-party email delivery and should have stricter per-IP/per-email limits (e.g., 10 requests/minute) than general API routes.+tag suffixes across providers and dot-insensitivity on Gmail/Googlemail so one mailbox cannot be used to farm unlimited trials.Does adding Turnstile hurt conversion for legitimate users? When configured in non-interactive or managed mode, Turnstile verifies most real browsers invisibly in the background without showing a visual puzzle, preserving signup conversion while blocking headless scripts and curl abuse.
Why check both action and hostname during Turnstile verification? Without hostname validation, an attacker can solve a challenge on a lower-security origin or staging domain and replay the token against your production API. Without action validation, a token minted on a low-risk form can be replayed against signup.
How do you do MX record lookups on Cloudflare Workers? Because node:dns is not available in workerd, use standard fetch against a DNS-over-HTTPS endpoint (application/dns-json) with type=MX, a tight AbortSignal.timeout, and short-TTL caching.
What order should auth checks run in? Run cheap, stateless checks first:
siteverify)At Ballet, we apply the same defense-in-depth engineering to AI agent operations—protecting customer-facing workflows from abuse while keeping onboarding seamless for real teams.