enhancement: Spam protection for the contact form (Cloudflare Turnstile, managed mode)
Back to our planProblem
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:
- Managed mode already does the requested flow in one widget: low-risk visitors pass with no interaction; only higher-risk visitors see a checkbox.
- Free plan: unlimited challenges, up to 20 widgets (https://developers.cloudflare.com/turnstile/plans/, opens in a new tab). reCAPTCHA now runs through Google Cloud with a 10,000 assessments/month free tier and billing beyond it (https://docs.cloud.google.com/recaptcha/docs/migration-overview, opens in a new tab). The project uses free tiers only.
- No ad-tracking cookies for residents; Cloudflare states WCAG 2.2 AAA compliance.
Implementation:
TurnstileWidgetclient component rendered in the Form block whenNEXT_PUBLIC_TURNSTILE_SITE_KEYis set; the token is sent with the submission.beforeChangehook on form submissions verifies the token server-side with Siteverify usingTURNSTILE_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.exampledocuments 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