Overview
Contact form abuse is when a bot (an automated program) or a person uses your website's contact form for something other than genuinely getting in touch. Common examples include spam messages, people pretending to be your business or staff, and injection attacks, which are attempts to hack your website through the form.
This article explains how to protect a website contact form using a layered set of proven techniques. Bots keep getting smarter, but these techniques can block almost all of this abuse. In most cases, your real visitors won't even notice them.
The layered approach
No single tool stops every unwanted message, so it's best to use several protections together. This is called a layered approach. The following options are listed from most to least important.
1. Server-side validation
Server-side validation means your web server checks everything typed into the form before the message is sent. This matters because client-side validation (checks done only in the visitor's web browser) is easy to get around, because bots can skip your form entirely and send data straight to your site. Many form plugins and website builders can handle server-side validation for you. If you're not sure yours does, ask your web developer.
2. Rate limiting
Rate limiting caps how many messages one visitor can send in a set amount of time, such as five per hour. Bots often try to send lots of messages very quickly, so a limit keeps them from flooding your form or inbox. Real visitors rarely send more than one message, so they won't be affected.
3. Modern CAPTCHA services
A CAPTCHA (Completely Automated Public Turing test to tell Computers and Humans Apart) is a tool that tells humans and bots apart. Modern CAPTCHAs mostly work in the background, looking at things like mouse movement, typing patterns, and browser details. This information is combined into a score. If the score shows that the request is legitimate, the submission goes through without any delay for the visitor. Only if the score is uncertain is the visitor asked to take an extra step, such as selecting a checkbox.
Popular CAPTCHA options include:
4. Honeypot fields
A honeypot field is an extra form field that people can't see, but bots can. Bots tend to fill in every field they find. If the hidden field has anything in it, your site knows a bot submitted the message and can throw it away.
5. Timing checks
Timing checks measure how long it takes for the form to be sent after the page loads. People need at least a few seconds to read the page and fill in the form, while bots fill it out and send it almost instantly. If the form is sent too quickly, your site can treat it as automated and discard it.
The best one-stop option
Using these techniques together gives you the strongest protection, because each one covers gaps the others might miss. If you can only do one thing, add a CAPTCHA service. A CAPTCHA service gives you the most protection for the least amount of effort.