Sub topic 7
Keeping bots off your list
This chapter assumes you can write a basic HTML form and read a little JavaScript. You should also know that your email service provider (ESP) stores subscribers and sends mail to them. Here you will learn how bots reach your list, how to block the simple ones, and what to do about the harder ones.
Why bots matter
Bots fill in public forms automatically. Some are spammers who want a link or a message to reach an inbox. Others submit thousands of random or stolen addresses. Some use your form to send unwanted mail to a victim, which is called list bombing.
Fake subscribers cause real problems:
- They inflate your subscriber count, so your conversion rate looks wrong.
- They raise bounce and spam-complaint rates, which harms your sender reputation.
- They can raise your bill, because many ESPs charge by list size.
Layer your defenses
No single check stops every bot. Use several cheap checks together, and add stronger ones only if abuse continues.
The honeypot field
A honeypot is a form field that humans never see but bots fill in. The sign-up form from the HTML chapter already has one, a field named website:
<div style="position:absolute;left:-9999px" aria-hidden="true">
<label for="website">Leave this field empty</label>
<input type="text" id="website" name="website" tabindex="-1" autocomplete="off">
</div>The field is moved off-screen instead of using display:none, because some bots skip fields they know are hidden. The tabindex="-1" and aria-hidden attributes keep keyboard and screen-reader users from landing in it. autocomplete="off" stops browsers from filling it in.
The check must happen on the server. A browser-side check does nothing against a bot that posts directly to your form URL.
from flask import Flask, request, abort
app = Flask(__name__)
@app.post("/subscribe")
def subscribe():
if request.form.get("website"):
# A person would have left this empty.
abort(400)
email = request.form.get("email", "").strip()
if "@" not in email or request.form.get("consent") != "yes":
abort(400)
# Queue a confirmation email here.
return "Check your inbox", 200Returning a generic error, or even a normal success page, gives the bot no hint about what failed.
Server-side validation and rate limits
The type="email" attribute and required only help honest users. Always validate again on the server: check the address format, check that the consent box was ticked, and cap the length of every field.
Add a rate limit too. For example, allow only a few submissions per IP address per minute, and only one confirmation email per address per hour. This stops list bombing, because your form can no longer be used to flood one inbox.
CAPTCHA and its costs
A CAPTCHA is a challenge meant to separate people from bots. Modern versions, such as Cloudflare Turnstile, hCaptcha, and reCAPTCHA, often run invisibly. Treat them as a second step, not the first. A challenge adds friction and can block people who use assistive technology. Some also load third-party scripts that raise privacy questions, which matters under the consent rules covered later.
Double opt-in as bot protection
Double opt-in sends a confirmation email, and the address joins the list only after the person clicks the link. A bot can still submit a fake address, but that address never confirms. Stolen addresses never confirm either, unless the real owner clicks. This is why double opt-in is covered in its own chapter as both a compliance and a hygiene tool.
Common mistakes
- Checking the honeypot only in JavaScript.
- Hiding the honeypot with
display:noneonly. - Forgetting to label the honeypot, which confuses screen-reader users who reach it.
- Showing a CAPTCHA to every visitor when a honeypot and rate limit would have been enough.
Exercise
A bot posts directly to your form's action URL, filling every field including the honeypot. Which check catches it, and why would a JavaScript-only check fail?
Show answer
The server-side honeypot check catches it, because the server sees the filled website field and rejects the request. A JavaScript-only check runs in the browser, and a bot that posts directly to the URL never runs your page's scripts.