Skip to content
SprecherEast
Issue 112

enhancement: Spam protection for the contact form (Cloudflare Turnstile, managed mode)

Back to our plan
Done
enhancementfrontendcmsconfigpriority: medium

Problem

The public contact form (fixed in #111 so it actually renders) accepts anonymous submissions with no spam protection. The seeded form also emails a confirmation to whatever address is typed in, so without a check a bot could use the site to send email to arbitrary addresses once email delivery is configured (#104).

The owner wants an "I'm not a robot" check that is invisible for most people and only shows a checkbox when the first check isn't confident.

Proposed fix

Use Cloudflare Turnstile in Managed mode rather than reCAPTCHA v3 with a v2 fallback:

Implementation:

  • TurnstileWidget client component rendered in the Form block when NEXT_PUBLIC_TURNSTILE_SITE_KEY is set; the token is sent with the submission.
  • beforeChange hook on form submissions verifies the token server-side with Siteverify using TURNSTILE_SECRET_KEY (required by Cloudflare; tokens are single-use and expire after 5 minutes). Admin/editor-created submissions skip the check.
  • Feature is off when keys aren't set, so local dev and CI keep working; .env.local.example documents Cloudflare's dummy test keys.

Server change (separate infra step, not in the PR): create a free Turnstile widget for sprechereast.com, then add both keys to the VPS .env.local before the deploy that ships this.

Acceptance criteria

  • Not done: With keys set, the contact form shows the Turnstile widget; most visitors pass without clicking.
  • Not done: A submission without a valid token is rejected server-side with a clear message, even when posted directly to /api/form-submissions.
  • Not done: A token can't be reused; the widget resets after each attempt.
  • Not done: With no keys set, forms work exactly as before (dev, CI).
  • Not done: Secret key never reaches the browser or the repo.

Area

frontend, cms, config

Priority

priority: medium


Generated by Claude Code, opens in a new tab

See it on GitHub, opens in a new tab