Software development
From Google reCAPTCHA to Cloudflare Turnstile: how to migrate and what you gain
Migrating from Google reCAPTCHA to Cloudflare Turnstile: widget, server‑side token verification, differences from the reCAPTCHA v3 score, CSP and benefits.
Fabio Folgori8 min read

For years, protecting a form meant one thing: Google reCAPTCHA. First the boxes of traffic lights to pick out, then the invisible version that scores every visitor. It worked, but at a price that weighs more today: a heavy script loaded from Google on every page that uses it, browsing data sent to a company that lives on advertising, and real users stuck in front of a puzzle while they try to ask for a quote.
Cloudflare Turnstile starts from the same need and solves it differently. I am trying it on the custom projects I am releasing at the moment, and the migration is shorter than you would expect, because the architecture is the same: a widget in the browser that produces a token, and a server that has it verified. The details change, and those are worth a closer look.
How Turnstile works
The widget runs a series of non-interactive checks in the browser: small computational challenges, checks on the environment the page runs in, behavioural signals. In most cases the visitor does nothing. Only when the signals are not enough does a checkbox appear; image puzzles do not exist.
When you create the widget you choose one of three modes:
- Managed: Cloudflare decides whether to show the checkbox. This is the recommended choice.
- Non-interactive: the widget is visible but never asks for an action.
- Invisible: nothing on screen, and verification is started from code.
At the end the widget delivers a token, which lands in a hidden form field called cf-turnstile-response. The token is valid for a few minutes and can be verified only once: two characteristics to keep in mind when writing the code.
The migration, step by step
The keys
In the Cloudflare dashboard you create a widget and list the domains it should work on. You get a public key (the sitekey), which goes in the page, and a secret key, which stays on the server only, among the environment variables. The site does not need to be hosted by Cloudflare.
The widget in the page
Remove the reCAPTCHA script and load the Turnstile one, then replace the container: instead of the element with the g-recaptcha class, use a <div> with the cf-turnstile class and the data-sitekey attribute. Alternatively, create the widget from code with turnstile.render(), which is the right route in single-page applications, where the form appears and disappears without a page reload.
There is also a compatibility mode that makes Turnstile answer to the reCAPTCHA names, useful when the markup cannot be touched. I treat it as a temporary bridge: it leaves names in the code that no longer match what actually runs.
Verification on the server
This is the step that matters. The server receives the form, reads the token and sends it in a POST request to the Turnstile siteverify endpoint together with the secret key. The response is JSON with the success field, the list of any errors, the domain the token was generated on and the action declared by the widget.
Compared with reCAPTCHA, three things change: the endpoint address, the key and the name of the field to read (cf-turnstile-response instead of g-recaptcha-response). If you were on reCAPTCHA v2, you are done here.
If you were on reCAPTCHA v3
v3 returns a score, and many applications built logic on top of it: above a threshold accept, below it ask for an email confirmation, lower still reject. Turnstile has no scores; it only says whether the challenge was passed. That logic has to be rewritten: it usually gets simpler, and where different behaviours were needed you use separate widgets with the action parameter, then check it in the server response.
The mistakes I see most often
- Verifying only in the browser. The widget callback that enables the submit button is not protection: an attacker calls the API directly and never sees the button. Without server‑side verification the captcha is decorative.
- Reusing the token. After a failed submission, for example a validation error, the token has already been consumed: the widget must be reset with
turnstile.reset(), otherwise the second attempt is rejected. - Forgetting the expiry. On a long form the user may take longer than the token lasts. The widget renews it on its own, but the code must read the value at submission time, not the one saved when the page opened.
- Not updating the Content Security Policy. If the site has a CSP, the
challenges.cloudflare.comdomain must be added for both scripts and frames, otherwise the widget does not appear and nobody understands why. - Testing with the real keys. Cloudflare provides test keys that always pass or always fail: they are meant for automated tests and for the local environment, where the domain is not among the authorised ones.
- Not checking the domain in the response. The
hostnamefield says where the token was generated: comparing it with your own domain costs one line.
The benefits, and the limits
The visitor feels the first benefit: almost always there is nothing to do. There are no images to recognise, and that matters for accessibility too, because visual puzzles are a serious obstacle for screen reader users.
The second is privacy. Turnstile sets no advertising cookies, and Cloudflare states that it does not use the data for profiling. For a European site that is a concrete argument, even if it does not close the matter on its own: it is still a third‑party service, to be mentioned in the privacy notice.
The third is weight: the script is lighter and does not block page loading. On a contact form at the bottom of a brochure page, the difference shows up in speed measurements.
Finally, cost: the free plan covers the normal use of a website or a management system, without the monthly thresholds reCAPTCHA introduced after moving to Google Cloud.
Then there is the benefit that weighed most for me: Turnstile connects to Supabase straight from the dashboard. In the authentication settings you pick Turnstile and paste the secret key: from then on Supabase verifies the token itself on sign‑up, sign-in and password recovery, with no dedicated function to write. reCAPTCHA is not among the options there (the choices are Turnstile and hCaptcha). For anyone building management systems on Supabase, as I describe in PostgreSQL vs MySQL: when to choose Supabase, it is less code to maintain.
There are limits. Without a score you lose the ability to grade the response. Protection depends on a provider, and if its service has a problem the form needs a planned behaviour. Above all, a captcha, whichever one, does not replace the rest: rate limits, server‑side validation, permission checks. It stops bots that fill in forms, not someone with an account trying to read another user's data. I cover those tests in how I attack my own systems locally before going live.
My take
There is no Turnstile on this site, and not by accident. I have a single form, the contact one, protected by Netlify's spam filter and an invisible honeypot field: adding a third service and one more script for a problem I do not have would go against my rule of few dependencies. On the applications I am releasing now it is a different story: there are logins, sign‑ups and forms that write to a database, and there I am trying it in place of reCAPTCHA. It convinced me quickly, and the Supabase integration was one of the reasons I switched: it integrates in little time, verification sits in a server function next to the rest of the API, the keys live in environment variables and every change goes through a preview before going live, as I describe in publishing a website with GitHub and Netlify.
My rule is simple: first the defences that cost the visitor nothing (honeypot field, rate limits, server‑side validation), then the captcha where a form really exposes something. And if a WordPress site is already the target of automated attacks, the captcha on the form is the least of its problems, as I explain in hacked WordPress site.
Why work with me
I have been building websites and applications since 1999 and have lived through every season of anti‑spam, from hidden fields to image puzzles. I can replace reCAPTCHA with Turnstile on your site or management system, put verification where it really belongs, on the server, and check that form protection is not the only defence. If you want to understand what makes sense in your case, get in touch or see the custom software development service.
Frequently asked questions
Yes. Turnstile is a standalone service: a Cloudflare account is enough to create the widget and get the two keys. The site can stay on any hosting, and the domain does not have to go through Cloudflare's DNS or proxy.
The server has to change too. The widget produces a token that proves nothing on its own: the server must send it to the Turnstile verification endpoint together with the secret key, and accept the request only if the answer is positive. The logic is the same as reCAPTCHA; the address, the keys and the field name change.
No. reCAPTCHA v3 returns a score from 0 to 1 and leaves the threshold to the developer. Turnstile returns an outcome: passed or not passed. If the application used different thresholds for different actions, that logic needs rethinking, for example with separate widgets and actions.
Turnstile does not use advertising cookies, and Cloudflare states that it does not use the collected data to profile users. It is still a third‑party service that receives technical data about the visitor: it belongs in the privacy notice, and the decision on consent is for whoever handles the legal side of the site.
- #turnstile
- #recaptcha
- #captcha
- #spam
- #security


