All posts
Engineering

A ten-layer spam defense for a contact form

A walkthrough of how we hardened our own contact form against bots, keyboard-mashers, and the increasingly creative LLM-generated junk hitting agency inboxes.

The Atlas Studio Team
March 22, 2026 10 min read
A contact form diagram

Our old contact form was getting 40+ spam messages a day. Half were classic bot-fill, a third were LLM hallucinations, and the rest were someone’s cat. Here is how we brought it to zero without adding a captcha.

The ten layers

  1. Hidden honeypot field (bots love to fill every input).
  2. Time-gate — reject submissions under 3 seconds.
  3. Per-IP rate limit — 3 per hour, in-memory token bucket.
  4. Email format sanity check, server-side, with MX lookup.
  5. Disposable-domain blocklist (refreshed nightly).
  6. Character dominance check — flag messages where one char is >35% of the body.
  7. Run-length check — flag any run of 5+ identical chars.
  8. Vowel ratio check — real prose sits in a narrow band.
  9. Word diversity — ratio of unique words to total.
  10. Cross-field mash — detect when name, email, and body are all the same keyboard smash.

The killer — statistical prose checks

Most spam filtering talks about tokens and phrases. Once an LLM is generating your spam, tokens stop working. But the shape of real writing — the ratio of vowels to consonants, the unique-word ratio, the distribution of character frequencies — is hard to fake by accident.

ts
// src/lib/spam-heuristics.ts
export function looksLikeGibberish(text: string): boolean {
  const s = text.toLowerCase().replace(/[^a-z ]/g, "");
  if (s.length < 12) return false;

  const chars: Record<string, number> = {};
  for (const c of s) chars[c] = (chars[c] ?? 0) + 1;

  const max = Math.max(...Object.values(chars));
  if (max / s.length > 0.35) return true;            // char dominance

  if (/(.)\1{4,}/.test(s)) return true;              // long run

  const vowels = (s.match(/[aeiou]/g) ?? []).length;
  const ratio = vowels / s.replace(/ /g, "").length;
  if (ratio < 0.2 || ratio > 0.6) return true;       // vowel band

  const words = s.split(/\s+/).filter(Boolean);
  const unique = new Set(words).size;
  if (words.length > 8 && unique / words.length < 0.4) return true;

  return false;
}

The result

40 a day down to 0 in the first week. Two false positives in the first month — both from people who wrote one-word messages like &ldquo;hi&rdquo;, which we now let through on length alone.


Want this level of polish on your own app?

We turn forms, flows, and follow-ups into things that feel handmade.

See what we build
Share Twitter LinkedIn
The Atlas Studio Team
Written by
The Atlas Studio Team
Studio

Short dispatches written jointly by our design + engineering team about how we work and what we care about.

Monthly

One studio dispatch. Every month.

What we shipped, what we read, and what we argued about. Zero filler, zero affiliates, one-click unsubscribe.

One email a month. Zero affiliates. One-click unsubscribe.