Skip to content
← All articles
9 min read

Contact form spam protection in Go without captcha: honeypots, headers, and reverse proxy bans

Stopping contact form spam without captcha requires layered defensive engineering: an invisible honeypot returning HTTP 204, strict Sec-Fetch-Site header validation, request body limits, and one-click IP banning via Telegram alerts. This architecture eliminates automated junk without killing conversion rates or adding friction for legitimate leads. Below is how to implement this clean anti-spam stack on a Go backend.

Why hidden inputs and client tokens fail to stop form spam

Most form spam is generated by automated bots scanning web pages for form elements. They parse input names, inject marketing payloads, and submit requests relentlessly. Common historical tricks, such as using an input with type="hidden" or setting display:none in inline CSS, became obsolete years ago. Modern scraping libraries analyze styles, computed DOM attributes, and field heuristics, allowing them to ignore obvious traps or deliberately omit them from the payload.

Relying on client-side JavaScript tokens or proof-of-work puzzles presents similar shortcomings. Headless browsers powered by Chromium execute JavaScript natively, generating valid session tokens and simulating mouse events effortlessly. Alternatively, attackers inspect client scripts, extract signing algorithms, and reproduce the payload in minimal Python or curl requests. Meanwhile, visual captchas hurt real business metrics by driving away mobile visitors and introducing unnecessary friction.

  • Inputs with type="hidden" or inline display:none styles: scrapers inspect the DOM tree and strip these inputs before dispatching payloads.
  • Client-generated JavaScript tokens: headless scrapers execute browser scripts automatically, making client calculations ineffective against targeted attacks.
  • Form submission time tracking: automated scrapers introduce synthetic delays to mimic human interaction speeds.
  • Mandatory image captchas: reduce spam at the expense of lower conversion rates and frustrated mobile prospects.

Honeypot fields: trap architecture and the silent HTTP 204 response

An effective honeypot is an input field invisible to human users but irresistible to automated scrapers. The field name must mimic realistic business data that bots routinely target, such as phone_secondary, user_website, company_fax, or middle_name. Naming the input honeypot, antispam, or bot_trap instantly signals the trap to parser heuristics. Position the field naturally among standard contact fields in the HTML markup.

Hiding the input from humans requires careful CSS styling. Never use the hidden HTML attribute or abrupt inline styles. Instead, assign an external utility class that displaces the input off-screen using absolute positioning, zero opacity, and collapsed dimensions. Always include tabindex="-1", aria-hidden="true", and autocomplete="off". These attributes prevent keyboard navigation from tabbing into the field, stop screen readers from announcing it, and prevent browser autofill engines from accidentally populating the input.

The critical architectural decision on the Go backend is how to react when a honeypot contains data. Returning HTTP 400 Bad Request or 403 Forbidden is a mistake. An error response tells the bot that it was caught, prompting the scraper script to refine its field combinations. When the Go handler detects a non-empty honeypot, it immediately halts processing and responds with HTTP 204 No Content (or HTTP 200 OK) with an empty body. The bot records a successful submission, while your database, CRM, and staff remain undisturbed.

Sec-Fetch-Site validation: shutting down cross-origin submissions

Modern browsers attach Fetch Metadata headers to outbound HTTP requests, which cannot be forged or modified by client-side JavaScript. The most valuable header for contact form protection is Sec-Fetch-Site. When a visitor submits a form on your landing page, the browser populates this header with the value same-origin. If an attacker triggers the submission from a third-party website via CSRF or an embedded iframe, the header reads cross-site. The Go backend must strictly reject any request where this value is not same-origin.

Be realistic about what this check does. Scripts that send raw HTTP requests often omit the header, and a missing header cannot be told apart from an old browser, so we let it through and reject only a value that is present and is not same-origin. That stops cross-site submissions from other pages, not a bot that sends no header. On sites built as static pre-rendered pages without JS it is one cheap layer, and the honeypot and the IP ban cover the rest. In our handler a mismatch gets a plain 403.

Complement Sec-Fetch-Site by validating Sec-Fetch-Mode, which should evaluate to navigate or cors during standard form interactions. Furthermore, inspect the Origin and Referer headers, verifying that their hostnames match your server domain precisely. A comprehensive approach to validating incoming request provenance is detailed in our guide on webhook security and signatures.

Defensive Go parsing: body limits, string sanitization, and truncation

Public form endpoints face memory exhaustion risks if inbound payloads are unbounded. Attackers frequently send massive POST bodies containing gigabytes of garbage or hundreds of affiliate links. In Go, the standard safeguard is wrapping the incoming request body with http.MaxBytesReader. Setting a conservative ceiling, such as thirty to sixty kilobytes, prevents memory bloat. If a client exceeds this limit, the reader raises an error, neutralizing simple DoS attempts.

Once parsed, every input string must undergo strict normalization and bounded truncation. Strip surrounding whitespace using strings.TrimSpace, remove non-printable control characters, and enforce tight length caps: names capped at one hundred characters, phone numbers at thirty, and message texts at one thousand. We build and refine these resilient ingestion pipelines as part of our dedicated Go backend development practice.

  • Request body restriction: wrapping r.Body with http.MaxBytesReader before decoding prevents heap exhaustion from bloated payloads.
  • Strict length caps: immediately truncating or rejecting string values exceeding realistic boundaries for names, emails, and comments.
  • Character normalization: removing non-printable Unicode characters, null bytes, and repetitive whitespace patterns.
  • Contact format sanity checks: validating email and phone structures with simple patterns without over-engineered regex edge cases.
  • Suspicious payload dropping: discarding submissions containing unescaped HTML tags or obvious injection patterns in plain-text inputs.

One-click Telegram IP bans and volume-backed blacklists

Even with robust filters, occasional spam submissions slip past defenses—especially when a human operator manually submits a promotional message. Handling these edge cases requires rapid administrative remediation. When a new submission arrives in the team chat, the notification includes an inline Telegram button labeled 'Ban IP'. The architecture behind connecting incoming leads to chat queues is explored in our article on Telegram bot CRM lead integration.

Clicking the button triggers a callback query handled by the bot service. The backend verifies the administrative privileges of the user, extracts the offending IP address, and appends it to a persistent blacklist file. This file resides on a mounted volume attached to the container, ensuring that blocked addresses persist across container redeployments, image upgrades, and host restarts.

In memory, the Go service maintains an active cache of the blacklist using a concurrent sync.Map or a slice guarded by a sync.RWMutex. The server initializes this cache from the volume on startup and synchronizes updates atomically. When incoming form requests arrive, checking the client IP against the in-memory blacklist takes sub-microsecond time, introducing zero disk I/O latency to standard request processing.

Reverse proxy filtering: ForwardAuth edge protection

When an aggressive bot or single compromised machine hammers your form endpoint repeatedly from a banned IP, processing every connection inside the Go application wastes compute resources. A superior operational architecture delegates IP enforcement to the edge reverse proxy, such as Traefik, Caddy, or Nginx with auth_request, using ForwardAuth.

Before routing incoming traffic to the application container, the reverse proxy dispatches a lightweight internal authorization check. This endpoint evaluates the client IP against the in-memory blacklist in microseconds. Consequently, malicious traffic never reaches your Go runtime, preserving CPU cycles and application connection pools.

When honeypots fall short: the reality of captchas and rate limits

The combination of honeypot fields, Sec-Fetch-Site validation, and reactive Telegram IP bans stops almost all automated spam on commercial landing pages and B2B contact forms. However, every engineering strategy has boundaries. Lightweight filtering cannot protect against two specific vectors: large-scale distributed botnets utilizing residential proxy pools, and manual crowd-spam executed by low-wage human contractors.

When spam requests arrive from thousands of unique residential IP addresses, banning individual IPs manually becomes futile. In these high-intensity scenarios, systems require automated rate limiting across CIDR subnet ranges alongside behavioral anti-bot challenges like Cloudflare Turnstile. The criteria below outline when simple honeypots suffice and when heavy defense becomes mandatory.

  • Honeypot and header validation suffice: standard B2B contact forms, landing pages, moderate traffic volumes, and common scraper engines.
  • Rate limiting required: persistent high-frequency submissions from rotating subnets, automated brute-force attempts, or registration endpoints.
  • Invisible behavioral captchas necessary: distributed residential botnet attacks, human crowd-spam campaigns, and sensitive checkout or lead generation flows where spam costs are punitive.
Questions

FAQ

Didn't find an answer — ask on the call or in Telegram.

How does contact form spam protection work without captcha?

Spam protection without captcha combines an invisible honeypot field, browser header checks such as Sec-Fetch-Site, request body size limits, and instant IP blacklisting via Telegram. Automated bots often fill the hidden honeypot, and the Go backend then silently discards the payload with an HTTP 204 No Content response.

Why should a honeypot field return HTTP 204 instead of a 400 error?

Returning HTTP 400 Bad Request or 403 Forbidden alerts scrapers that their submission failed, prompting the bot script to inspect the response and adjust its payload. Returning HTTP 204 No Content or 200 OK tricks the bot into registering a successful delivery, terminating the attack while protecting your CRM from junk.

Why verify the Sec-Fetch-Site header on contact forms?

Sec-Fetch-Site is an unforgeable browser metadata header. A value of same-origin confirms the request was initiated from your own domain rather than a cross-site CSRF script. A request that carries a value other than same-origin, for example a form posted from another site, is rejected before the form data is parsed.

How does one-click IP banning work via Telegram?

When a lead notification reaches Telegram, the message includes an inline button with the sender IP address. An administrator clicks the button, prompting the backend to verify permissions and write the IP into a file on a mounted volume. The server caches this blacklist in memory for instant subsequent filtering.

Why use ForwardAuth at the reverse proxy level for IP blacklists?

During sustained spam floods, routing rejected requests through the application runtime consumes server threads and memory. ForwardAuth allows edge proxies like Traefik or Caddy to verify incoming IPs before forwarding requests, terminating malicious connections at the perimeter and protecting the Go application from resource exhaustion.

When are captchas or rate limits truly necessary?

Captchas and rate limiting become indispensable against distributed residential botnets with thousands of rotating IP addresses, human crowd-spam campaigns, and high-value transaction endpoints. In those environments, single-IP blacklists and honeypot traps cannot prevent coordinated submission abuse, requiring behavioral challenges and subnet-wide throttling.

Related service

Go backend development for business applications

We build the server side of web products and develop existing systems. Data, traffic and reliability requirements come first, so the architecture fits the work it needs to do.

Learn about the service
Other articles
Contact

Shall we discuss your task?

Thirty minutes on a call — and you understand the architecture, timeline and engagement format. No obligations.

Or message us on Telegram →Follow our Telegram channel →

Enter your Telegram or email so we can reply.

We reply within 15 minutes.