Stop Contact Form Spam: Honeypot, Timing Check, Turnstile
How to cut contact form spam: a hidden honeypot field, a timing check and Cloudflare Turnstile compared, and why the token must be checked on the server.
In this post
Contact form spam is a message a script or a person sends to your form without wanting anything from your visitors or your business. It reaches you because the form is public and its address can be found. Three layers can reduce it: a hidden honeypot field, a timing check, and a bot test such as Cloudflare Turnstile. This post explains how each one works, what it asks of the visitor, and where it fails, then shows why a bot test protects nothing unless the server checks its token.
What contact form spam is and why it reaches you
A contact form is a page on your site that accepts input from anyone. The browser sends whatever the visitor typed to the URL in the form's action, and the receiving end handles it. The receiving end usually does not know who sent the message, so it cannot tell a person from a script by default.
Spam arrives in two forms. Some is automated: a script fills in the fields and presses submit, often thousands of times. Some is written by a person, who may be selling something or testing your inbox. The three layers below are aimed mostly at the automated kind. None of them will identify a determined person, and none of them is a complete answer on its own.
Honeypot field
A honeypot is an extra field in the form that a visitor should never see or fill in. You hide it from people, usually with CSS, and give it a name that looks like a normal field, such as a company or website field. A script that fills every field it finds will also fill this one. The receiving end then checks whether the field has a value, and if it does, it treats the submission as suspicious.
For the visitor, the honeypot costs nothing: they never see it and never type in it. The weak point is that it only catches scripts that fill in every field. A script written to skip hidden fields, or to fill only the fields it recognises, will not trigger it. The honeypot also depends on the receiving end checking the value. A honeypot that is hidden on the page but never checked on the server does nothing.
Timing check
A timing check records when the form was rendered and compares that with when it was submitted. A submission that arrives within an implausibly short time is treated as suspicious. The receiving end sets the threshold, and it is a choice you make and test, not a standard value.
For the visitor, the timing check is invisible. For you, the risk is a false positive: a genuine visitor who fills in the form quickly, for example with autofill, may be flagged. The check also fails against a script that waits before it submits. Use it as one signal among several, and log what it flags, so you can see whether it blocks real messages.
Bot test with Cloudflare Turnstile
Cloudflare Turnstile is a bot test that works in two parts. According to the Turnstile get-started guide, a JavaScript widget runs challenges in the visitor's browser and produces a token. The token is a string of up to 2,048 characters, generated when the visitor completes a challenge. The form then sends that token with the submission, and the server checks it with Cloudflare.
What the widget asks of the visitor depends on its configuration, so read the current Turnstile documentation before you promise visitors a specific experience.
The token has two limits that matter for your code. It expires after 300 seconds, and each token can be validated only once. A token that is old or has already been checked must be replaced with a new challenge.
Why the widget alone protects nothing
The widget on the page proves nothing to your server. Anyone can send a request to your form with any text in the token field, so the only check that counts is the one your server makes.
The server-side validation guide says what that check looks like. Your server sends a POST request to https://challenges.cloudflare.com/turnstile/v0/siteverify, with two required parameters: secret, which is your widget's secret key, and response, which is the token the form submitted. Beyond the success field in the answer, the guide says to validate the action and hostname fields when they are specified, so that a token from another flow or another site is rejected.
Two more rules from the same guide matter in practice. The secret key must stay on your backend, because anyone who sees it in front-end code can skip the check. And a token that has expired or has already been validated returns the error timeout-or-duplicate, which means the token expired or was already validated. The fix is to request a new token for a new submission, not to retry the old one.
What to do with suspected spam instead of deleting it
A flagged submission is not always spam. A false positive from the timing check or the honeypot can throw away a real enquiry, and you will not know unless you keep a record. Store flagged submissions separately, with the reason they were flagged, and review them on a schedule. Deleting them at once removes the evidence you need to tune the three layers.
Keep the flagged copies out of your main inbox, so that real messages stay visible. Do not send them to the visitor, and do not reply to the sender of a flagged message until you have checked it.
Combining the three
The three layers catch different things, so they work better together than one alone. The honeypot and the timing check cost the visitor nothing and catch simple scripts. Turnstile adds a challenge that is harder to pass, and its token can be checked on the server. A reasonable setup uses all three: the honeypot and timing check run on the server first, and Turnstile is verified before a submission is accepted.
The order matters less than the rule that every layer is checked on the server. A layer that only runs in the browser can be bypassed by anyone who sends a request directly, so the server is where the decision belongs.
Spam across many sites
If you run several sites, each form needs its own set of checks, and each site needs its own Turnstile widget and secret key. The server check for each site must use the matching secret, and the hostname check exists for exactly this reason: a token issued for one site should not be accepted on another. Keep a list of the widgets and their secrets, and know which site each one belongs to, so a changed key on one site does not silently break another.
Spam is also easier to read when it is grouped. If the same pattern shows up on several sites, one review of the flagged copies can tell you which rule is catching real messages and which is letting spam through. That review is easier if all the flagged submissions reach one place. How Prosphere works describes the planned approach to one inbox for many sites, which is still in build. You can also see the shared inbox plan and the contact page for the waitlist.
Sources
- Cloudflare Turnstile, get started: https://developers.cloudflare.com/turnstile/get-started/
- Cloudflare Turnstile, server-side validation: https://developers.cloudflare.com/turnstile/get-started/server-side-validation/