We started the series from an incident: our contact form turned into a phishing relay, with 109 emails sent from our domain, and then we went through eight layers of defense in three articles. In the final part, we put it all together: what each layer stops, what a handler looks like where everyone has their place, a checklist, and the mistakes that practically cancel all protections.
Applied Security Series for Web Forms:
- Part 1: what the attacker wants and form design
- Part 2: validation, signed tokens, and challenge
- Part 3: rate limiting, scoring, email, and monitoring
- Part 4: conclusions and checklist (this article)
The eight layers, on a single page
| Layer | What it stops | Where we discussed it |
|---|---|---|
| 1. Form design | The reason for abuse: nothing is sent to the visitor's address | Part 1 |
| 2. Validation and encoding | Oversized data, HTML injected into email and admin panel | Part 2 |
| 3. Honeypot and minimum signed time | Naive bots and forged timings | Part 2 |
| 4. Server-verified challenge | Automated attack, including those with rotating IPs | Part 2 |
| 5. Rate limiting on multiple keys | Volume: per IP, global, and per address | Part 3 |
| 6. Content scoring | What passes all technical filters but looks like abuse | Part 3 |
| 7. Email isolation | Domino effect on the company’s email | Part 3 |
| 8. Monitoring and kill switch | An attack that lasts days without anyone noticing | Part 3 |
Putting it all together: the handler
Each layer only makes sense in the right order. Rate limiting runs as middleware, before the handler. In the handler, cheap and local checks run first, the call to the challenge provider only after, and saving happens regardless of the result:
static async Task<IResult> HandleContactAsync(
ContactForm form, HttpContext http, FormTimingToken timing, TurnstileVerifier turnstile,
SubmissionScorer scorer, IContactStore store, IContactMailer mailer,
IFeatureManager features, CancellationToken ct)
{
// 1. Cheap checks first
if (!string.IsNullOrEmpty(form.Website) || !timing.IsHumanPace(form.TimingToken, TimeSpan.FromSeconds(3)))
return Results.Ok(); // same response as success
// 2. Challenge, an external call, only after
if (!await turnstile.VerifyAsync(form.TurnstileToken, http.Connection.RemoteIpAddress?.ToString(), ct))
return Results.BadRequest(); // here a real visitor must retry
// 3. Scoring and saving, always
var (score, hits) = scorer.Evaluate(form);
var blocked = score >= SubmissionScorer.Threshold;
await store.SaveAsync(form, score, hits, blocked, ct);
// 4. Email only to the team, only if not blocked and kill switch allows
if (!blocked && await features.IsEnabledAsync("ContactFormEmail"))
await mailer.NotifyTeamAsync(form, ct);
return Results.Ok();
}
Note two decisions. The honeypot and scoring respond the same as success, so the attacker does not learn what stopped them. The failed challenge, however, returns an error because a real person might need to retry there. And the email is sent only to the team, never to the entered address, according to the rule from the first part.
Checklist for any public form
- The form does not send anything controlled by the visitor to an address controlled by the visitor.
- Responses are identical for existing and non-existing accounts.
- Each field has a length limit validated on the server.
- The email subject and sender are fixed, and the visitor's address appears only in Reply-To, validated.
- Visitor content is encoded wherever displayed: email, admin panel, exports.
- The honeypot and minimum time use a token signed on the server.
- The challenge token is verified on the server with each submission, including hostname and action.
- You have explicitly decided what happens when the challenge service does not respond.
- Rate limiting on at least two keys: per IP and global per endpoint.
- The real IP is correctly read behind the proxy, with known proxies configured.
- Rate limiting counters survive a restart and are shared between instances.
- Submissions, including blocked ones, are saved with score and rules for analysis and filter testing.
- SPF, DKIM, and DMARC are configured, and DMARC has a plan to move to quarantine or reject.
- Application emails are sent from a subdomain and through a provider separate from the team’s mailbox.
- There is a volume alert and a kill switch that stops sending without a deploy.
- Endpoints triggering paid operations have a cost cap.
Common mistakes
- Trusting a single layer. "We have CAPTCHA" or "we have rate limiting" is the beginning of the discussion, not the end.
- CAPTCHA verified only in the browser. Without server verification, the widget is decorative.
- Rate limiting on the proxy IP. All visitors share the same limit, and the form seems to work until the day it matters.
- Error messages too precise. "The message contains a forbidden link in the name" tells the attacker exactly what to change.
- The form sends through the company’s email inbox. Abuse of the form becomes a problem for all company communication.
- Filters changed without corpus. Without real data, each new rule is a guess, and false positives are discovered from customers.
Conclusions
If you take away only one thing from the series, let it be this: a public form is an endpoint that does something on behalf of anyone. The security question is not "how do I stop bots?", but "what can a stranger do through my form?".
- Design beats filtering. The cheapest and strongest layer is the one that eliminates the reason for the attack. What sends nothing outside cannot be turned into an email relay.
- Each layer stops a different attacker. The honeypot stops naive bots, the challenge stops automation, global rate limiting caps volume, scoring catches what remains. None works alone, and together they make the attack expensive enough not to be worth it.
- Cap the damage, not just the requests. A global cap on the endpoint and a cost cap on paid operations limit what can happen in the worst case.
- Isolate the effects. A subdomain and a dedicated provider for application emails mean an incident remains a form incident, not the whole company’s.
- Find out first. Logs, volume alert, and kill switch make the difference between an attack stopped in minutes and one discovered by the email provider after three days.
If you haven’t read the story that started the series, you can find it in Anatomy of a coordinated attack on a contact form. And if you have also experienced form abuse, I would like to know which layer failed and what worked.