Turnstile is Cloudflare’s CAPTCHA replacement for your own forms: a widget that runs browser checks instead of making humans transcribe traffic lights, free to use, and — unlike the zone-level security products — it works on any site, even one not proxied by Cloudflare. The architecture is two halves and both are mandatory: the widget produces a token in the browser, and your server exchanges that token with Cloudflare’s siteverify endpoint before trusting the submission. A Turnstile deployment without the server-side check is decoration, and that is the single most common way it “fails”.
What’s happening
Zone-level defenses — the evaluation chain of IP Access rules, WAF custom rules, rate limiting, managed rulesets, and the bot products (Bot Fight Mode on Free, Super Bot Fight Mode on Pro and Business) — judge requests before they reach your app, but they cannot know which POST to /contact deserves extra scrutiny. Turnstile moves that judgment into the form itself. The widget, loaded from challenges.cloudflare.com, runs the same style of non-interactive browser signals as Managed Challenge and issues a one-time token bound to your sitekey. Your backend then POSTs the token plus your secret key to siteverify; the answer says whether the token is genuine, fresh (tokens expire after 300 seconds), and unused (each token validates once).
Three widget modes set the visible behaviour: Managed lets Cloudflare decide per visitor, showing an interactive checkbox only when signals are weak — the right default. Non-Interactive shows a passive widget that never asks for interaction. Invisible renders nothing at all. Mode changes what users see, not the security model — the token-and-verify loop is identical. For sites that are also behind Cloudflare’s proxy, an optional pre-clearance setting can let a Turnstile solve double as the zone’s clearance cookie, cutting duplicate challenges.
What to check first
- Where the spam actually enters. Turnstile protects the forms you put it on; comment spam through an API route or a legacy endpoint walks straight past it.
- That your form flow has a server side. Static forms posting to third-party services need that service to support Turnstile verification — the secret key must never ship to the browser.
- Your CSP, if you have one.
script-srcandframe-srcmust permitchallenges.cloudflare.comor the widget will not render. - How long users sit on the form. Tokens live 300 seconds; a long checkout or a draft-heavy contact form needs token refresh handled.
How to verify
Prove the server half works with the dummy keys before touching production keys — the test sitekey 1x00000000000000000000AA always issues a passing token, and its sibling secret always validates:
# Server-side verification - the step everyone skips
curl -s "https://challenges.cloudflare.com/turnstile/v0/siteverify" \
--data "secret=$TURNSTILE_SECRET" \
--data "response=$TOKEN_FROM_FORM" \
--data "remoteip=$CLIENT_IP"
# Expect: {"success":true,...}
# Failure tells you why: {"success":false,"error-codes":["timeout-or-duplicate"]}
Then confirm rejection paths: submit the same token twice (must fail the second time), submit with the token field stripped (must fail), and watch the browser console on a test page — a wrong or unauthorized hostname surfaces as widget error 110200. Finally, check your zone is not fighting itself:
Security > Events
Filter: Path equals /contact, Method equals POST
A challenge or block here means a zone rule is eating submissions
before Turnstile's token ever reaches your server.
The fix
-
Create the widget. In the Cloudflare dashboard, open Turnstile, add a widget, list every hostname that will serve the form (including staging), pick Managed mode, and record the sitekey (public) and secret key (server-only).
-
Embed the widget in the form.
<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" async defer></script> <form method="POST" action="/contact"> <div class="cf-turnstile" data-sitekey="0x4AAAAAAAAxxxxxxx" data-theme="auto"></div> <button type="submit">Send</button> </form>The widget injects a hidden
cf-turnstile-responsefield into the form on success. -
Verify server-side on every submission. Reject when
successis false, and treat a missing token as a rejection, not a pass. Log theerror-codes— they distinguish expired tokens from replays from misconfiguration. -
Handle expiry and resubmits. Keep the default auto-refresh behaviour for expired tokens, and after a failed form validation round-trip, force a fresh token rather than resubmitting the old one —
timeout-or-duplicateis almost always a reused token. -
Wire it into your CMS instead of hand-rolling where possible. WordPress form and comment plugins have Turnstile integrations that do the verify step correctly — the comment-spam comparison in Akismet, Antispam Bee and Turnstile for comments covers that path.
-
Keep test keys out of production. The always-pass sitekey in a deployed template means every bot passes; grep your templates for
1x00000000000000000000AAbefore shipping.
When this fix is wrong
Turnstile is per-form human verification, not traffic defense: against scraping, credential stuffing across your login API, or floods, you want the zone-level products — the tier comparison in bot management tiers maps that landscape. It is also the wrong tool for machine-to-machine endpoints: webhooks and API clients can never solve a widget, so protect those with keys and allowlists instead.
Common mistakes
- Rendering the widget but never calling
siteverify— the token is a claim, not proof, until your server checks it. - Shipping the secret key to the browser or a public repo.
- Verifying only on the happy path and skipping the check when the token field is absent.
- A CSP that blocks
challenges.cloudflare.com, leaving a blank spot where the widget should be — for privacy-browser users only, which makes it maddening to reproduce. - Forgetting staging hostnames in the widget config, so QA sees
110200errors that production never shows.
Prevention
Alert on the ratio of form submissions to successful siteverify calls: a growing gap means either an integration break or a replay attempt, and both deserve attention the same day. Rotate the secret if it ever lands in a repo, and re-test the double-submit and expiry paths after each form refactor. The official reference, including error codes and testing keys, is at developers.cloudflare.com/turnstile/.
Tuning edge security so it blocks attacks without blocking customers is ongoing work — Stack Harbor watches those events around the clock under 24/7 Monitoring & Response; book a monitoring and response review.