Honeypots for bot detection: hidden fields and trap links
Short answer
A honeypot is a trap that people never trigger because they cannot see it or have no reason to use it, while automated clients do. Common forms are a hidden form field that bots fill in, a time check that rejects forms submitted too fast, a hidden link to a path that polite crawlers are told to avoid, and decoy URLs that only scanners request.
A honeypot works because people and scripts read a page differently. A person sees the rendered page and interacts with what is visible. Many bots read the HTML, fill every field and follow every link. Anything that is present in the HTML but invisible to people becomes a cheap test, and it adds no friction for real visitors.
How does a honeypot form field work?
Add an extra input that is moved off screen with CSS. People never see it, so they leave it empty. Generic spam bots fill it in.
<form method="post" action="/signup">
<label for="email">Email</label>
<input type="email" id="email" name="email" autocomplete="email" required>
<div class="hp-field" aria-hidden="true">
<label for="extra_info">Leave this field empty</label>
<input type="text" id="extra_info" name="extra_info" tabindex="-1" autocomplete="off">
</div>
<button type="submit">Create account</button>
</form>.hp-field {
position: absolute;
left: -10000px;
width: 1px;
height: 1px;
overflow: hidden;
}Positioning off screen is harder for a bot to spot than type="hidden" or display: none, which some form bots skip. aria-hidden and tabindex="-1" keep the field away from screen readers and keyboard users, and the label tells anyone who still reaches it what to do.
Choose a field name that browser autofill and password managers do not recognise. Names that contain words such as email, phone, address, company or name can get filled automatically, which turns real customers into false positives. Test the form in Chrome, Safari, Firefox and at least one password manager before going live.
On the server, reject filled submissions without showing an error. Returning the normal success response gives the bot operator nothing to learn from. An Express middleware:
function honeypot(fieldName) {
return (req, res, next) => {
if (req.body && req.body[fieldName]) {
console.warn('honeypot hit', { ip: req.ip, path: req.path, ua: req.get('user-agent') });
return res.status(200).send('Thanks, we will be in touch.');
}
next();
};
}
app.post('/signup', express.urlencoded({ extended: false }), honeypot('extra_info'), signupHandler);How does a time trap work?
People need several seconds to read and fill a form. Many bots submit within milliseconds of loading it. Put a signed timestamp in the form and reject submissions that arrive too fast or too late. Signing it with HMAC stops a bot from sending its own timestamp.
const crypto = require('node:crypto');
const SECRET = process.env.FORM_SECRET;
function sign(value) {
return crypto.createHmac('sha256', SECRET).update(value).digest('hex');
}
function issueFormToken() {
const ts = Date.now().toString();
return `${ts}.${sign(ts)}`;
}
function checkFormToken(token, minMs = 2000, maxMs = 24 * 60 * 60 * 1000) {
const [ts, sig] = String(token || '').split('.');
if (!ts || !sig) return false;
const expected = sign(ts);
if (sig.length !== expected.length) return false;
if (!crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(expected))) return false;
const age = Date.now() - Number(ts);
return age >= minMs && age <= maxMs;
}Render issueFormToken() into a hidden input and call checkFormToken() on submit. Two seconds is a starting point for a short form like a newsletter signup; raise it for longer forms. The upper limit stops a bot from reusing one token for days. Within that window a harvested token can still be replayed many times, so if reuse matters, include a session ID in the signed value or record tokens that have already been used. Do not use a time trap on login forms, where password managers let real users submit within a second.
How do trap links work?
A trap link is a link that people cannot see and polite crawlers are told not to follow. Disallow the path in robots.txt:
User-agent: *
Disallow: /trap/Add one hidden link to it, using the same off-screen class:
<a href="/trap/catalog-index" class="hp-field" rel="nofollow" tabindex="-1" aria-hidden="true">Catalog index</a>Major search crawlers follow the Robots Exclusion Protocol (RFC 9309), and people never see the link. A client that requests /trap/ either ignored robots.txt or read it looking for paths to visit, so it is not a polite crawler. What robots.txt does and does not stop explains why the file alone is no defence. Log those hits separately in nginx:
location ^~ /trap/ {
access_log /var/log/nginx/trap.log combined;
return 404;
}Then ban the IPs for a short time with fail2ban:
# /etc/fail2ban/filter.d/nginx-trap.conf
[Definition]
failregex = ^<HOST> -# /etc/fail2ban/jail.d/nginx-trap.conf
[nginx-trap]
enabled = true
port = http,https
filter = nginx-trap
logpath = /var/log/nginx/trap.log
maxretry = 1
findtime = 3600
bantime = 3600
ignoreip = 127.0.0.1/8 ::1Publish the Disallow rule at least a day before you add the link, because crawlers may cache robots.txt for up to 24 hours under RFC 9309 and could follow the link before they see the new rule. Before banning, check trap hits against verified crawlers, and add your own monitoring and office IPs to ignoreip. Keep the ban short, because the IP may be shared by an office, a mobile carrier or a household. If your site sits behind a CDN, nginx logs the CDN's addresses unless you configure the real client IP header, and a firewall ban on the origin does not stop traffic that arrives through the CDN. In that case, apply the block at the CDN. Blocking bots with nginx and Apache covers the real IP setup.
What other decoys can you set?
- Requests for
/wp-login.phpor/.envon a site that runs neither WordPress nor exposed config files come from scanners. Log them and treat the source as hostile for a while. - An API endpoint that appears in your JavaScript bundle but that your app never calls will only be requested by someone reading your code to build a scraper.
- A few user accounts that nobody uses act as canaries. A login attempt against one means your user list has leaked or someone is testing which usernames exist.
What do honeypots miss?
Bots that drive a real browser and interact only with visible elements skip hidden fields and hidden links. An operator who targets your site will inspect the form once and leave the trap empty from then on. Honeypots remove generic spam bots and careless crawlers at no cost to real users. For the rest, combine them with rate limits, behavioural signals and an invisible challenge, as described in how to stop bots from submitting forms. The logs from your traps are also a useful input for detecting bot traffic across the site.
Tools that help
StopBots is published by Kairal, which is one of the tools listed. The list is not a ranking.
- fail2ban is free and open source, reads log files such as the trap log above and bans offending IPs at the firewall, enough for a single server.
- CrowdSec is open source, detects scanners and brute force from your logs and shares blocklists with its community, which suits sites that see many hidden-file searches.
- Akismet filters comment and form spam on WordPress through a hosted service, a good complement to a honeypot field on contact forms.
- Wordfence is a WordPress security plugin with a firewall and login protection, and it has a free version.
- Kairal protects signup, login and other forms per endpoint and verifies suspicious visitors with invisible challenges, for sites where targeted bots get past simple traps.
Common questions
Is a honeypot better than a CAPTCHA?
It is better for users, because nobody sees it, and worse against targeted bots, because an operator who looks at your form once will leave the hidden field empty. Many sites use a honeypot first and show a challenge only when other signals are suspicious.
Can honeypots hurt SEO?
A hidden form field has no effect on search. A trap link is safe for search engines as long as its path is disallowed in robots.txt and marked nofollow, because verified crawlers such as Googlebot obey robots.txt. Check that you never block verified crawler IPs by mistake.
Do spam bots still fall for honeypot fields?
Generic form spam bots, which fill every input they find in the HTML, still do. Bots built for one site, or bots that drive a real browser and fill only visible fields, usually do not.