A post going around X this week put it in one line: "Vibe coding a website is great until you realize you forgot to add spam protection or rate limiting to your forms." Around the same time, a write-up made the rounds about an AI-built booking app wired to Stripe, OpenAI, Supabase and Resend. None of its keys had spending caps, and it logged 212 unauthorized requests in two weeks.

Neither one surprised me. When we generate marketing sites, the contact form, the waitlist box, or the "book a demo" form is usually the only part with a backend. It's also the part nobody looks at after the first test message shows up in the inbox. The page loads, the form works, ship it.

So I wanted to see what that form actually allows. I wrote the kind of /api/contact handler a coding agent produces when you ask for "a working contact form that emails us and sends the visitor a confirmation". Then I wrote a script that abuses it the way bots and bored people do, hardened the handler, and ran the same script again. Everything runs locally. The email API is a stub that counts what it would have sent, so no real email went anywhere. All the numbers below come from those runs.

It doesn't matter whether the site came from Cursor, Claude Code or an AI website builder. If there's a form that triggers an email, this applies.

The naive handler

This is a fictional invoicing product called Ledgerly, with a Vercel-style serverless function. Generated code tends to come out in roughly this shape:

// What a coding agent typically writes for "add a working contact form that emails us // and sends the visitor a confirmation". Deliberately naive. Do not ship this. import { mailer as resend } from "../mailer.mjs"; export const formHtml = `<form method="post" action="/api/contact"> <input name="name" placeholder="Your name" required> <input name="email" type="email" placeholder="you@company.com" required> <textarea name="message" required></textarea> <button>Send</button> </form>`; export default async function handler(req, res) { if (req.method !== "POST") return res.status(405).end(); const { name, email, message } = req.body; // notify the team await resend.emails.send({ from: "Ledgerly <hello@ledgerly.example>", to: "team@ledgerly.example", replyTo: email, subject: `New message from ${name}`, html: `<p><b>${name}</b> (${email}) wrote:</p><p>${message}</p>`, }); // confirm to the visitor await resend.emails.send({ from: "Ledgerly <hello@ledgerly.example>", to: email, subject: `Thanks for reaching out, ${name}!`, html: `<p>Hi ${name},</p><p>Thanks for contacting Ledgerly. We'll get back to you within 24 hours.</p>`, }); return res.status(200).json({ ok: true }); } 

It looks harmless. It validates nothing, and every POST sends two emails. One goes to your team. The other goes to whatever address the request claims, with the request's name in the subject and body. That second email is the problem.

The harness

Three small pieces, Node only, no dependencies:

  • mailer.mjs stands in for the email client. emails.send() pushes the message into an in-memory array and returns a fake id. No network.
  • server.mjs is a tiny stand-in for the platform. It parses JSON, applies a 5 MB body limit, sets req.ip, and mounts the handler. It lets the test script fake client IPs through an X-Test-Client-IP header so one machine can play many clients. A real platform works out the client IP itself. Never trust a client-supplied header for this in production.
  • attack.mjs starts a fresh server for each attack (so rate-limit state doesn't leak between tests), fires requests, then reads the stub's outbox and counts what got through.

The attacks:

Attack What it does
form-bot 50 posts from a bot that loads the form, fills every field it finds, and submits instantly
fast-bot 50 posts from a bot that skips hidden fields but still submits in under a second
replay one form token reused for 20 posts
burst 200 posts from one IP in a tight loop
autoreply-bomb 100 posts with victim@example.net as the sender, from 100 different IPs
distributed 300 posts from 300 IPs with 300 different sender addresses (quota drain)
crlf "Bob\r\nBcc: everyone@list.example" as the name
phish-name "Account locked! Verify: https://ledgerly-verify.example" as the name, victim's address as sender
html-message an <a href> "invoice overdue, pay here" link in the message
oversized a 1 MB message

There's also a control: one normal message from a person, to make sure the hardening doesn't break the form.

Note that burst, autoreply-bomb, distributed and replay are run by a careful attacker. It loads the form first, keeps any token it finds, leaves hidden fields empty, and waits a few seconds before firing. I did that on purpose. Bot checks stop lazy scripts, and I wanted to see what's left once someone puts in a little effort.

attack.mjs (about 135 lines)
// Fires realistic abuse at a local contact endpoint and reports what reached the email API. // Usage: node attack.mjs naive|hardened [--json out.json] // Everything stays on 127.0.0.1. The "email API" is the in-memory stub in mailer.mjs. import { spawn } from "node:child_process"; import { writeFileSync } from "node:fs"; const target = process.argv[2]; const jsonOut = process.argv.includes("--json") ? process.argv[process.argv.indexOf("--json") + 1] : null; const TEAM = "team@ledgerly.example", VICTIM = "victim@example.net"; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); async function withServer(fn) { const child = spawn(process.execPath, ["server.mjs", target, "0"], { cwd: new URL(".", import.meta.url).pathname, env: { ...process.env, MIN_FILL_MS: "3000", DAILY_SEND_CAP: "50" }, }); const p = await new Promise((ok, bad) => { child.stdout.on("data", (d) => { const m = String(d).match(/on :(\d+)/); if (m) ok(m[1]); }); child.on("exit", (c) => bad(new Error(`server exited ${c}`))); }); const base = `http://127.0.0.1:${p}`; try { return await fn(base); } finally { child.kill(); } } const getForm = async (base) => (await fetch(`${base}/contact`)).text(); const fields = (html) => [...html.matchAll(/<(?:input|textarea)[^>]*name="([^"]+)"(?:[^>]*value="([^"]*)")?/g)].map((m) => [m[1], m[2] || ""]); async function post(base, body, ip = "203.0.113.7") { const r = await fetch(`${base}/api/contact`, { method: "POST", headers: { "content-type": "application/json", "x-test-client-ip": ip }, body: JSON.stringify(body), }); let j = {}; try { j = await r.json(); } catch {} return { status: r.status, reason: j.reason || j._dropped || null }; } // A careful attacker reads the form: keeps any token, leaves unknown hidden fields alone, // and waits out a minimum fill time once for a whole batch of pre-fetched forms. async function patientTokens(base, n) { const toks = []; for (let i = 0; i < n; i++) { const t = fields(await getForm(base)).find(([k]) => k === "token"); toks.push(t ? t[1] : undefined); } if (toks.some(Boolean)) await sleep(3100); return toks; } async function run(name, what, fn) { return withServer(async (base) => { const results = await fn(base); const outbox = await (await fetch(`${base}/__outbox`)).json(); const reasons = {}; for (const r of results) if (r.reason) reasons[r.reason] = (reasons[r.reason] || 0) + 1; const unsafe = outbox.filter((m) => /[\r\n]/.test(m.subject) || /https?:\/\//.test(m.subject) || (m.to !== TEAM && /https?:\/\//.test(m.html || "")) || /<a\s|<script/i.test(m.html || "")); return { name, what, requests: results.length, accepted: results.filter((r) => r.status >= 200 && r.status < 300).length, emails: outbox.length, toOutsiders: outbox.filter((m) => m.to !== TEAM).length, toVictim: outbox.filter((m) => m.to === VICTIM).length, unsafe: unsafe.length, bytesToProvider: outbox.reduce((s, m) => s + (m.html || "").length + (m.text || "").length + (m.subject || "").length, 0), reasons, sample: (() => { const m = unsafe.find((x) => x.to !== TEAM) || unsafe[0]; return m ? { to: m.to, subject: m.subject, html: (m.html || "").slice(0, 160) } : null; })(), }; }); } const attacks = [ ["control", "1 normal human submission (should still work)", async (b) => { const [token] = await patientTokens(b, 1); return [await post(b, { name: "Dana Ortiz", email: "dana@smallshop.example", message: "Do you support CSV export for my accountant?", token })]; }], ["form-bot", "50 bot posts that fill every field and submit instantly", async (b) => { const out = []; for (let i = 0; i < 50; i++) { const body = {}; for (const [k, v] of fields(await getForm(b))) body[k] = v || ({ name: "Crypto Bonus", email: `bot${i}@spam.example`, message: "Claim your bonus at https://spam.example" }[k] || "https://spam.example"); out.push(await post(b, body, "198.51.100.23")); } return out; }], ["fast-bot", "50 bot posts that skip hidden fields but submit within 1s", async (b) => { const out = []; for (let i = 0; i < 50; i++) { const tok = fields(await getForm(b)).find(([k]) => k === "token"); out.push(await post(b, { name: "Promo", email: `fast${i}@spam.example`, message: "cheap backlinks, reply now", token: tok && tok[1] }, "198.51.100.24")); } return out; }], ["replay", "1 aged form token reused for 20 posts", async (b) => { const [token] = await patientTokens(b, 1), out = []; for (let i = 0; i < 20; i++) out.push(await post(b, { name: "Kim", email: `kim${i}@replay.example`, message: "same token again", token }, `172.16.0.${i + 1}`)); return out; }], ["burst", "200 posts from one IP in a tight loop", async (b) => { const toks = await patientTokens(b, 200), out = []; for (let i = 0; i < 200; i++) out.push(await post(b, { name: "Sam", email: `sam${i}@flood.example`, message: "hello hello", token: toks[i] })); return out; }], ["autoreply-bomb", `100 posts with ${VICTIM} as the sender, 100 different IPs`, async (b) => { const toks = await patientTokens(b, 100), out = []; for (let i = 0; i < 100; i++) out.push(await post(b, { name: "Alex", email: VICTIM, message: "pls call me back", token: toks[i] }, `192.0.2.${i + 1}`)); return out; }], ["distributed", "300 posts, 300 IPs, 300 sender addresses (quota drain)", async (b) => { const toks = await patientTokens(b, 300), out = []; for (let i = 0; i < 300; i++) out.push(await post(b, { name: "Lee", email: `lee${i}@many.example`, message: "question about pricing", token: toks[i] }, `10.${i >> 8}.${i & 255}.9`)); return out; }], ["crlf", "CRLF + fake Bcc header in the name field", async (b) => { const [token] = await patientTokens(b, 1); return [await post(b, { name: "Bob\r\nBcc: everyone@list.example", email: "bob@example.org", message: "hi there", token })]; }], ["phish-name", "phishing text + URL in name, victim's address as sender"Source:https://dev.to/polydraft/your-vibe-coded-contact-form-is-a-free-email-relay-i-attacked-mine-to-find-out-1op2

Related posts